SlideShare uma empresa Scribd logo
1 de 57
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
Usage in the software world
• Queue or schedule
• Reversible operations
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
Usage in the software world
• Dynamic composition of objects at runtime
• No control over who gets information
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
Usage in the software world
• Library logic separate à easy to change
• No unwanted logic all over codebase
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
Usage in the software world
• Don’t know all the types beforehand
• Extending library
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
Usage in the software world
• Fewer changes when skeleton changes
• Force structure
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
Usage in the software world
• Home automation
• Multiple facades for complex subsystem
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

Semelhante a Design pattern talk by Kaya Weers - 2024 (v2)

Breaking up with dewey
Breaking up with deweyBreaking up with dewey
Breaking up with deweyRachel Fewell
 
getting started on wikis, blogs, iCal, and more
getting started on wikis, blogs, iCal, and moregetting started on wikis, blogs, iCal, and more
getting started on wikis, blogs, iCal, and moretim wojcik
 
Music City Agile - KonMari your Backlog: Tidying up those PBIs
Music City Agile - KonMari your Backlog: Tidying up those PBIsMusic City Agile - KonMari your Backlog: Tidying up those PBIs
Music City Agile - KonMari your Backlog: Tidying up those PBIsJulie Wyman
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeffAlexander Sapountzis
 
Designing Your UX Career
Designing Your UX CareerDesigning Your UX Career
Designing Your UX CareerBen Sykes
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme FrameworkJoe Casabona
 
Phuong phap trien khai 5S trong doanh nghiep
Phuong phap trien khai 5S trong doanh nghiepPhuong phap trien khai 5S trong doanh nghiep
Phuong phap trien khai 5S trong doanh nghiepnguyenanvuong2007
 
Lyddie: Unit3 lesson7
Lyddie: Unit3 lesson7Lyddie: Unit3 lesson7
Lyddie: Unit3 lesson7Terri Weiss
 
Discussion Tracking with BIRT: A Greek Tragedy in Two Acts
Discussion Tracking with BIRT: A Greek Tragedy in Two ActsDiscussion Tracking with BIRT: A Greek Tragedy in Two Acts
Discussion Tracking with BIRT: A Greek Tragedy in Two ActsMichael Shelmet
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDDKonstantin Kudryashov
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"Inhacking
 
Using Libguides to Corral Your Workflows
Using Libguides to Corral Your WorkflowsUsing Libguides to Corral Your Workflows
Using Libguides to Corral Your WorkflowsCharleston Conference
 

Semelhante a Design pattern talk by Kaya Weers - 2024 (v2) (13)

Breaking up with dewey
Breaking up with deweyBreaking up with dewey
Breaking up with dewey
 
getting started on wikis, blogs, iCal, and more
getting started on wikis, blogs, iCal, and moregetting started on wikis, blogs, iCal, and more
getting started on wikis, blogs, iCal, and more
 
Music City Agile - KonMari your Backlog: Tidying up those PBIs
Music City Agile - KonMari your Backlog: Tidying up those PBIsMusic City Agile - KonMari your Backlog: Tidying up those PBIs
Music City Agile - KonMari your Backlog: Tidying up those PBIs
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
 
Designing Your UX Career
Designing Your UX CareerDesigning Your UX Career
Designing Your UX Career
 
Building a Simple Theme Framework
Building a Simple Theme FrameworkBuilding a Simple Theme Framework
Building a Simple Theme Framework
 
Phuong phap trien khai 5S trong doanh nghiep
Phuong phap trien khai 5S trong doanh nghiepPhuong phap trien khai 5S trong doanh nghiep
Phuong phap trien khai 5S trong doanh nghiep
 
Lyddie: Unit3 lesson7
Lyddie: Unit3 lesson7Lyddie: Unit3 lesson7
Lyddie: Unit3 lesson7
 
Discussion Tracking with BIRT: A Greek Tragedy in Two Acts
Discussion Tracking with BIRT: A Greek Tragedy in Two ActsDiscussion Tracking with BIRT: A Greek Tragedy in Two Acts
Discussion Tracking with BIRT: A Greek Tragedy in Two Acts
 
Moving away from legacy code with BDD
Moving away from legacy code with BDDMoving away from legacy code with BDD
Moving away from legacy code with BDD
 
SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"SE2016 Java Alex Theedom "Java EE revisits design patterns"
SE2016 Java Alex Theedom "Java EE revisits design patterns"
 
Alex Theedom Java ee revisits design patterns
Alex Theedom	Java ee revisits design patternsAlex Theedom	Java ee revisits design patterns
Alex Theedom Java ee revisits design patterns
 
Using Libguides to Corral Your Workflows
Using Libguides to Corral Your WorkflowsUsing Libguides to Corral Your Workflows
Using Libguides to Corral Your Workflows
 

Último

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Design pattern talk by Kaya Weers - 2024 (v2)

  • 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 Usage in the software world • Queue or schedule • Reversible operations
  • 14. Kaya Weers | Ordina 10 minutes later..
  • 15. Kaya Weers | Ordina They cannot find the coffee
  • 16. Kaya Weers | Ordina “Sigh…“
  • 17. 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
  • 18. Kaya Weers | Ordina Observer pattern • One-to-many relationship • When the state from an object changes, all dependencies are notified • Loose coupling
  • 19. Kaya Weers | Ordina Observer pattern (subject) (Observers) StockUpdate Bobby Customer 1 Customer 2 register(observer)
  • 20. Kaya Weers | Ordina Observer pattern (Observers) StockUpdate Bobby Customer 1 Customer 2 notifyObservers() update() update() update() (subject)
  • 21. Kaya Weers | Ordina * constructors omitted for readability *
  • 22. Kaya Weers | Ordina Usage in the software world • Dynamic composition of objects at runtime • No control over who gets information
  • 23. Kaya Weers | Ordina The next product.. .. is also a challenge
  • 24. Kaya Weers | Ordina But, the text is in.. Spanish!
  • 25. Kaya Weers | Ordina Luckily, it’s 2024
  • 26. 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
  • 27. 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
  • 28. Kaya Weers | Ordina Adapter pattern (client) (client interface) (adapter) Billie Product Spanish Product Product Translator getIngredients() getIngredients InSpanish() getIngredients() (service) interface
  • 29. Kaya Weers | Ordina * constructors omitted for readability *
  • 30. Kaya Weers | Ordina Usage in the software world • Library logic separate à easy to change • No unwanted logic all over codebase
  • 31. Kaya Weers | Ordina Last on their list..
  • 32. Kaya Weers | Ordina They go to the bakery
  • 33. Kaya Weers | Ordina They enter the French bakery
  • 34. 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
  • 35. 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
  • 36. Kaya Weers | Ordina Factory method pattern Bread WholeGrain SlicedBread interface Baguette Bakery Supermarket Bakery createBread() createBread() abstract class French Bakery createBread() factory method
  • 37. Kaya Weers | Ordina * constructors omitted for readability *
  • 38. Kaya Weers | Ordina Usage in the software world • Don’t know all the types beforehand • Extending library
  • 39. Kaya Weers | Ordina The smell of the bakery .. made them hungry.
  • 40. Kaya Weers | Ordina The baker prepares the sandwiches
  • 41. Kaya Weers | Ordina The baker follows steps
  • 42. 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
  • 43. Kaya Weers | Ordina Template method pattern • Superclass defines a skeleton • Subclasses have specific implementation for steps • Superclass can contain (default) implementation
  • 44. Kaya Weers | Ordina Template method pattern Sandwich Chicken Sandwich prepare() addFirstLayer() addFirstLayer() abstract class Vegetable Sandwich addFirstLayer() template method
  • 45. Kaya Weers | Ordina * constructors omitted for readability *
  • 46. Kaya Weers | Ordina Usage in the software world • Fewer changes when skeleton changes • Force structure
  • 47. Kaya Weers | Ordina With both their shopping bags and bellies full.. they go home
  • 48. Kaya Weers | Ordina They drop the bag at the floor
  • 49. Kaya Weers | Ordina 5 min later..
  • 50. 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
  • 51. Kaya Weers | Ordina Facade pattern • Simplified interface for client • Client doesn’t need to know about subsystem • Removes complexity from the interface
  • 52. Kaya Weers | Ordina Facade pattern Bobby Freezer putAwayGroceries() Cabinet Refrigerator Pantry (client) Mom (facade)
  • 53. Kaya Weers | Ordina * constructors omitted for readability *
  • 54. Kaya Weers | Ordina Usage in the software world • Home automation • Multiple facades for complex subsystem
  • 55. Kaya Weers | Ordina Summary Command Observer Adapter Facade Template method Factory method
  • 56. Kaya Weers | Ordina Going to the supermarket.. will never be the same again
  • 57. Kaya Weers | Ordina THANK YOU @KayaWeers /KayaWeers