SlideShare une entreprise Scribd logo
1  sur  57
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à 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
 

Similaire à 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
 

Dernier

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Dernier (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
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
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
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
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

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