SlideShare a Scribd company logo
1 of 57
Download to read 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

More Related Content

Similar to 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
 

Similar to 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
 

Recently uploaded

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 

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