SlideShare uma empresa Scribd logo
1 de 51
Baixar para ler offline
A design pattern
goes to the supermarket
Kaya Weers
Kaya Weers | Ordina
First, an important question..
Kaya Weers | Ordina
So… Design Patterns?
Design patterns don’t give you code.
They provide general, reusable solutions for the common
problems in software design
Blueprints that you can customize.
Kaya Weers | Ordina
A bit of history
• Book by the Gang of Four (1994)
• 23 patterns, in 3 categories
• Ways to solve problems
• Same vocabulary
Kaya Weers | Ordina
Let me introduce you:
Bobby
Billie
Kaya Weers | Ordina
On a Saturday afternoon..
Kaya Weers | Ordina
When..
Kaya Weers | Ordina
She said:
Kaya Weers | Ordina
So, what’s the pattern?
• Mom wants groceries
• She writes her request on a note: what needs to be
done by who.
• Little sister’s tasks is to bring the note to the table
• Bobby knows how to handle the request on the note
Kaya Weers | Ordina
Command pattern
• Encapsulates request as a stand-alone object
• Decouple trigger from the content request
• Invoker doesn’t need to know content of request
Kaya Weers | Ordina
Command pattern
(client) (invoker) (Command)
(receiver)
Mom Little Sister Note
DoGroceries
Note
Bobby
interface
setCommand(note) execute()
execute()
doGroceries()
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
10 minutes later..
Kaya Weers | Ordina
They cannot find the coffee
Kaya Weers | Ordina
“Sigh…“
Kaya Weers | Ordina
So, what’s the pattern?
• Bobby asks employee when the coffee will be back in
stock
• Employee doesn’t know at that moment
• Employee doesn’t want customers to ask him again
• Customers can sign up to be notified as soon as the
product is available
Kaya Weers | Ordina
Observer pattern
• One-to-many relationship
• When the state from an object changes,
all dependencies are notified
• Loose coupling
Kaya Weers | Ordina
Observer pattern
(subject)
(Observers)
StockUpdate
Bobby
Customer 1
Customer 2
register(observer)
Kaya Weers | Ordina
Observer pattern (Observers)
StockUpdate
Bobby
Customer 1
Customer 2
notifyObservers()
update()
update()
update()
(subject)
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
The next product..
.. is also a challenge
Kaya Weers | Ordina
But, the text is in..
Spanish!
Kaya Weers | Ordina
Luckily, it’s 2024
Kaya Weers | Ordina
So, what’s the pattern?
• Billie wants to read the ingredients
• But Billie can’t read Spanish
• Translation app converts the Spanish words to
English words
• Billie can read English
Kaya Weers | Ordina
Adapter pattern
• Lets classes work together that couldn’t otherwise,
because of incompatible interfaces
• The adapter converts an interface into an interface
that the client expects
• More generic interface
Kaya Weers | Ordina
Adapter pattern
(client) (client interface)
(adapter)
Billie Product
Spanish
Product
Product
Translator
getIngredients()
getIngredients
InSpanish()
getIngredients()
(service)
interface
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
Last on their list..
Kaya Weers | Ordina
They go to the bakery
Kaya Weers | Ordina
They enter the French bakery
Kaya Weers | Ordina
So, what’s the pattern?
• Order supermarket bakery: ‘bread’
• Order French bakery: ‘bread’
• Different result: different variants of bread
• Creation differs per location
Kaya Weers | Ordina
Factory method pattern
• Interface for creating objects in superclass
• Object creation in subclass, can alter the type of
objects
• Easy to extend: add new creator subclasses
Kaya Weers | Ordina
Factory method pattern
Bread
WholeGrain
SlicedBread
interface
Baguette
Bakery
Supermarket
Bakery
createBread()
createBread()
abstract class
French
Bakery
createBread()
factory method
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
The smell of the bakery
.. made them hungry.
Kaya Weers | Ordina
The baker prepares the sandwiches
Kaya Weers | Ordina
The baker follows steps
Kaya Weers | Ordina
So, what’s the pattern?
• Bobby and Billie order two different sandwiches
• The baker creates them with different ingredients
• Most of the steps are the same, easy for baker
• Some steps are optional, like the topping
Kaya Weers | Ordina
Template method pattern
• Superclass defines a skeleton
• Subclasses have specific implementation for steps
• Superclass can contain (default) implementation
Kaya Weers | Ordina
Template method pattern
Sandwich
Chicken
Sandwich
prepare()
addFirstLayer()
addFirstLayer()
abstract class
Vegetable
Sandwich
addFirstLayer()
template method
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
With both their shopping bags and
bellies full..
they go home
Kaya Weers | Ordina
They drop the bag at the floor
Kaya Weers | Ordina
5 min later..
Kaya Weers | Ordina
So, what’s the pattern?
• Mom gives 1 instruction: “put away groceries”
• Bobby and Billie put everything in the right place
• Mom gives no specific instructions
• Mom doesn’t need to know about steps taken
Kaya Weers | Ordina
Facade pattern
• Simplified interface for client
• Client doesn’t need to know about subsystem
• Removes complexity from the interface
Kaya Weers | Ordina
Facade pattern
Bobby
Freezer
putAwayGroceries()
Cabinet Refrigerator Pantry
(client)
Mom
(facade)
Kaya Weers | Ordina
* constructors omitted for readability *
Kaya Weers | Ordina
Summary
Command Observer Adapter
Facade
Template method
Factory method
Kaya Weers | Ordina
Going to the supermarket..
will never be the same again
Kaya Weers | Ordina
THANK YOU
@KayaWeers
/KayaWeers

Mais conteúdo relacionado

Mais procurados

Microservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaMicroservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaEdureka!
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenarioArnauld Loyer
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Edureka!
 
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...Simplilearn
 
Getting Started With Docker | Docker Tutorial | Docker Training | Edureka
Getting Started With Docker | Docker Tutorial | Docker Training | EdurekaGetting Started With Docker | Docker Tutorial | Docker Training | Edureka
Getting Started With Docker | Docker Tutorial | Docker Training | EdurekaEdureka!
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean ArchitectureMattia Battiston
 
Git interview questions | Edureka
Git interview questions | EdurekaGit interview questions | Edureka
Git interview questions | EdurekaEdureka!
 
KubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdfKubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdfWeaveworks
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring FrameworkHùng Nguyễn Huy
 
Introduction to DevOps slides.pdf
Introduction to DevOps slides.pdfIntroduction to DevOps slides.pdf
Introduction to DevOps slides.pdfBoreVishnusai
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with LaravelMichael Peacock
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in DockerDocker, Inc.
 

Mais procurados (20)

Microservices Design Patterns | Edureka
Microservices Design Patterns | EdurekaMicroservices Design Patterns | Edureka
Microservices Design Patterns | Edureka
 
BDD - Writing better scenario
BDD - Writing better scenarioBDD - Writing better scenario
BDD - Writing better scenario
 
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
Java Interview Questions and Answers | Spring and Hibernate Interview Questio...
 
DevOps: Infrastructure as Code
DevOps: Infrastructure as CodeDevOps: Infrastructure as Code
DevOps: Infrastructure as Code
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
What Is A Docker Container? | Docker Container Tutorial For Beginners| Docker...
 
Getting Started With Docker | Docker Tutorial | Docker Training | Edureka
Getting Started With Docker | Docker Tutorial | Docker Training | EdurekaGetting Started With Docker | Docker Tutorial | Docker Training | Edureka
Getting Started With Docker | Docker Tutorial | Docker Training | Edureka
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Real Life Clean Architecture
Real Life Clean ArchitectureReal Life Clean Architecture
Real Life Clean Architecture
 
Git interview questions | Edureka
Git interview questions | EdurekaGit interview questions | Edureka
Git interview questions | Edureka
 
Introduction to container based virtualization with docker
Introduction to container based virtualization with dockerIntroduction to container based virtualization with docker
Introduction to container based virtualization with docker
 
KubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdfKubeCon 2022 EU Flux Security.pdf
KubeCon 2022 EU Flux Security.pdf
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Gitlab ci-cd
Gitlab ci-cdGitlab ci-cd
Gitlab ci-cd
 
Introduction to DevOps slides.pdf
Introduction to DevOps slides.pdfIntroduction to DevOps slides.pdf
Introduction to DevOps slides.pdf
 
API Development with Laravel
API Development with LaravelAPI Development with Laravel
API Development with Laravel
 
Kubernetes in Docker
Kubernetes in DockerKubernetes in Docker
Kubernetes in Docker
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 

Último

Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Último (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 

Design pattern talk by Kaya Weers - 2024

  • 1. A design pattern goes to the supermarket Kaya Weers
  • 2. Kaya Weers | Ordina First, an important question..
  • 3. Kaya Weers | Ordina So… Design Patterns? Design patterns don’t give you code. They provide general, reusable solutions for the common problems in software design Blueprints that you can customize.
  • 4. Kaya Weers | Ordina A bit of history • Book by the Gang of Four (1994) • 23 patterns, in 3 categories • Ways to solve problems • Same vocabulary
  • 5. Kaya Weers | Ordina Let me introduce you: Bobby Billie
  • 6. Kaya Weers | Ordina On a Saturday afternoon..
  • 7. Kaya Weers | Ordina When..
  • 8. Kaya Weers | Ordina She said:
  • 9. Kaya Weers | Ordina So, what’s the pattern? • Mom wants groceries • She writes her request on a note: what needs to be done by who. • Little sister’s tasks is to bring the note to the table • Bobby knows how to handle the request on the note
  • 10. Kaya Weers | Ordina Command pattern • Encapsulates request as a stand-alone object • Decouple trigger from the content request • Invoker doesn’t need to know content of request
  • 11. Kaya Weers | Ordina Command pattern (client) (invoker) (Command) (receiver) Mom Little Sister Note DoGroceries Note Bobby interface setCommand(note) execute() execute() doGroceries()
  • 12. Kaya Weers | Ordina * constructors omitted for readability *
  • 13. Kaya Weers | Ordina 10 minutes later..
  • 14. Kaya Weers | Ordina They cannot find the coffee
  • 15. Kaya Weers | Ordina “Sigh…“
  • 16. Kaya Weers | Ordina So, what’s the pattern? • Bobby asks employee when the coffee will be back in stock • Employee doesn’t know at that moment • Employee doesn’t want customers to ask him again • Customers can sign up to be notified as soon as the product is available
  • 17. Kaya Weers | Ordina Observer pattern • One-to-many relationship • When the state from an object changes, all dependencies are notified • Loose coupling
  • 18. Kaya Weers | Ordina Observer pattern (subject) (Observers) StockUpdate Bobby Customer 1 Customer 2 register(observer)
  • 19. Kaya Weers | Ordina Observer pattern (Observers) StockUpdate Bobby Customer 1 Customer 2 notifyObservers() update() update() update() (subject)
  • 20. Kaya Weers | Ordina * constructors omitted for readability *
  • 21. Kaya Weers | Ordina The next product.. .. is also a challenge
  • 22. Kaya Weers | Ordina But, the text is in.. Spanish!
  • 23. Kaya Weers | Ordina Luckily, it’s 2024
  • 24. Kaya Weers | Ordina So, what’s the pattern? • Billie wants to read the ingredients • But Billie can’t read Spanish • Translation app converts the Spanish words to English words • Billie can read English
  • 25. Kaya Weers | Ordina Adapter pattern • Lets classes work together that couldn’t otherwise, because of incompatible interfaces • The adapter converts an interface into an interface that the client expects • More generic interface
  • 26. Kaya Weers | Ordina Adapter pattern (client) (client interface) (adapter) Billie Product Spanish Product Product Translator getIngredients() getIngredients InSpanish() getIngredients() (service) interface
  • 27. Kaya Weers | Ordina * constructors omitted for readability *
  • 28. Kaya Weers | Ordina Last on their list..
  • 29. Kaya Weers | Ordina They go to the bakery
  • 30. Kaya Weers | Ordina They enter the French bakery
  • 31. Kaya Weers | Ordina So, what’s the pattern? • Order supermarket bakery: ‘bread’ • Order French bakery: ‘bread’ • Different result: different variants of bread • Creation differs per location
  • 32. Kaya Weers | Ordina Factory method pattern • Interface for creating objects in superclass • Object creation in subclass, can alter the type of objects • Easy to extend: add new creator subclasses
  • 33. Kaya Weers | Ordina Factory method pattern Bread WholeGrain SlicedBread interface Baguette Bakery Supermarket Bakery createBread() createBread() abstract class French Bakery createBread() factory method
  • 34. Kaya Weers | Ordina * constructors omitted for readability *
  • 35. Kaya Weers | Ordina The smell of the bakery .. made them hungry.
  • 36. Kaya Weers | Ordina The baker prepares the sandwiches
  • 37. Kaya Weers | Ordina The baker follows steps
  • 38. Kaya Weers | Ordina So, what’s the pattern? • Bobby and Billie order two different sandwiches • The baker creates them with different ingredients • Most of the steps are the same, easy for baker • Some steps are optional, like the topping
  • 39. Kaya Weers | Ordina Template method pattern • Superclass defines a skeleton • Subclasses have specific implementation for steps • Superclass can contain (default) implementation
  • 40. Kaya Weers | Ordina Template method pattern Sandwich Chicken Sandwich prepare() addFirstLayer() addFirstLayer() abstract class Vegetable Sandwich addFirstLayer() template method
  • 41. Kaya Weers | Ordina * constructors omitted for readability *
  • 42. Kaya Weers | Ordina With both their shopping bags and bellies full.. they go home
  • 43. Kaya Weers | Ordina They drop the bag at the floor
  • 44. Kaya Weers | Ordina 5 min later..
  • 45. Kaya Weers | Ordina So, what’s the pattern? • Mom gives 1 instruction: “put away groceries” • Bobby and Billie put everything in the right place • Mom gives no specific instructions • Mom doesn’t need to know about steps taken
  • 46. Kaya Weers | Ordina Facade pattern • Simplified interface for client • Client doesn’t need to know about subsystem • Removes complexity from the interface
  • 47. Kaya Weers | Ordina Facade pattern Bobby Freezer putAwayGroceries() Cabinet Refrigerator Pantry (client) Mom (facade)
  • 48. Kaya Weers | Ordina * constructors omitted for readability *
  • 49. Kaya Weers | Ordina Summary Command Observer Adapter Facade Template method Factory method
  • 50. Kaya Weers | Ordina Going to the supermarket.. will never be the same again
  • 51. Kaya Weers | Ordina THANK YOU @KayaWeers /KayaWeers