SlideShare une entreprise Scribd logo
1  sur  51
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
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

Contenu connexe

Tendances

GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact versionscalaconfjp
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.jsRyan Anklam
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVMRomain Schlick
 
Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Apigee | Google Cloud
 
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...Amazon Web Services
 
Quarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesQuarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesRed Hat Developers
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud VMware Tanzu
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Edureka!
 

Tendances (20)

GraalVM
GraalVMGraalVM
GraalVM
 
GraalVM Overview Compact version
GraalVM Overview Compact versionGraalVM Overview Compact version
GraalVM Overview Compact version
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
PHP Presentation
PHP PresentationPHP Presentation
PHP Presentation
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
Express js
Express jsExpress js
Express js
 
Modern UI Development With Node.js
Modern UI Development With Node.jsModern UI Development With Node.js
Modern UI Development With Node.js
 
Spring boot
Spring bootSpring boot
Spring boot
 
Discover Quarkus and GraalVM
Discover Quarkus and GraalVMDiscover Quarkus and GraalVM
Discover Quarkus and GraalVM
 
Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?Which Application Modernization Pattern Is Right For You?
Which Application Modernization Pattern Is Right For You?
 
Jira 101
Jira 101Jira 101
Jira 101
 
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...
Deep Dive into Firecracker Using Lightweight Virtual Machines to Enhance the ...
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Quarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniquesQuarkus tips, tricks, and techniques
Quarkus tips, tricks, and techniques
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Introduction to CI/CD
Introduction to CI/CDIntroduction to CI/CD
Introduction to CI/CD
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
Lambda Expressions in Java | Java Lambda Tutorial | Java Certification Traini...
 

Dernier

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
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
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Dernier (20)

Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
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
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
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
 
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...
 

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