SlideShare a Scribd company logo
1 of 61
Design Patterns 05/28/10 Week 3: Factory Method and Abstract Factory Jonathan Simon [email_address]
Agenda ,[object Object],[object Object],[object Object],[object Object],05/28/10
Head First Webpage ,[object Object],[object Object],[object Object],[object Object],05/28/10
Tangent : Preventing Future Mistakes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Preventing Future Mistakes (cont) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 The method DoSomething() is overwriting behavior in the superclass.
Preventing Future Mistakes (cont) ,[object Object],[object Object],[object Object],[object Object],05/28/10
Preventing Future Mistakes (cont) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Technical Debt 05/28/10 Source: http://martinfowler.com/bliki/TechnicalDebtQuadrant.html
Review: What Pattern should we consider? ,[object Object],[object Object],[object Object],05/28/10
Today’s Class ,[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Pizza Store in Objectville ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
PizzaStore in Objectville ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
PizzaStore in Objectville  (pg 112 top) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 This method is responsible for creating the pizza.  It calls methods to prepare, bake, etc.  Pizza is returned to caller.
PizzaStore in Objectville (pg 112 middle) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Code that varies A parameter indicating type Code that stays the same
PizzaStore in Objectville (cont) ,[object Object],[object Object],[object Object],05/28/10
Solution?  (pg 115) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
SimplePizzaFactory ,[object Object],[object Object],05/28/10
Rework of PizzaStore (pg 116) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Store is  composed  of a factory. Creation of pizza is delegated to factory.
Simple Factory Defined (pg 117) ,[object Object],[object Object],[object Object],[object Object],05/28/10
Change Now Occurs… ,[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Example (pg 119) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
More change happens… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
More change happens… (cont) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
What New York wants ,[object Object],[object Object],[object Object],05/28/10
A Framework for Pizza Store (pg 120) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 NOTE : We are using  inheritance  here to create the pizzas, not composition. Also, the constructor for PizzaStore has been removed.
NYPizzaStore (pg 123) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 The subclass is defining how the pizza is created….and it is also providing unique functionality that is applicable to New York.
Factory Method ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Factory Method simply sets up an interface for creating a Product (in this case, a type of Pizza).  Subclasses decide which specific Product to create.
Test Drive (pg 127) ,[object Object],[object Object],[object Object],[object Object],05/28/10
Factory Method Defined ,[object Object],05/28/10
Definitions (pg 134) ,[object Object],[object Object],[object Object],[object Object],05/28/10
IMPORTANT ,[object Object],05/28/10
Lab ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 ,[object Object],[object Object],[object Object],[object Object]
Parameterized  Factory Method ,[object Object],[object Object],[object Object],05/28/10
Simple Factory Method ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Simple Factory Method (with Default) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 In this example, there is default Product created (DefaultPizza).
Back to SimUDuck (pg 16) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Developer would have to  know  to do this.  The design does not enforce it. MallardDuck is tied to two specific implementations.
Before ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
After ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Factory Methods
Now we create MallardDuck… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Developer is “forced” to specify implementations of Fly and Quack. Note that the constructor is empty.
Alternative Design: Default Behavior ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 MallardDuck does not  have  to implement these methods.
Factory Method and Template ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Example re-worked here
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Changes.. ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Pizza  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Pizza becomes composed of different ingredients. Question: How do we get these ingredients associated with a Pizza??
One idea…Constructor w/many parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Makes sense…whenever you create a pizza, you must specify these ingredients…
Rework NYPizzaStore ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 This will cause a lot of maintenance headaches!!!  Imagine what happens when we create a new pizza!  We know that we have a certain set of ingredients that are used for New York..yet we have to keep repeating that set with each constructor.  Can we define this unique set just once??
PizzaIngredientFactory (pg 146) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Create an interface for creating the different ingredients of Pizza. Note that each ingredient of Pizza has a corresponding method defined in the interface.
NYPizzaIngredientFactory (pg 147) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Here we see the set of ingredients that are specific to the NY region. Note  that each time a createXXX() method is called, a new instance is returned.  This will be important later on.
CheesePizza (pg 150) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Instead of many ingredient parameters, we just pass one. Does this remind you of another pattern?? Creation delegated Note: Not all ingredients have to be used!
NYPizzaStore (pg 152) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 The specific ingredient factory is defined once for the NY region.
Abstract Factory Defined ,[object Object],05/28/10
Factory Method vs. Abstract Factory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Database Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
DatabaseFactory ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10 Each database implementation (Oracle, SQL Server, etc) will need to create their own version of this DatabaseFactory. The specific DatabaseFactory must be sent to the constructor of the framework class DatabaseManager.
Abstract Factory and Singleton ,[object Object],[object Object],05/28/10
A more interesting case… ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
What will happen?? ,[object Object],[object Object],05/28/10
Solution: Abstract Factory and Prototype ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Solution: Abstract Factory and Prototype ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10
Abstract Factory: Last Thoughts ,[object Object],[object Object],05/28/10
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],05/28/10

More Related Content

Viewers also liked

Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
Vaibhav Bajaj
 

Viewers also liked (17)

Factory Design Pattern
Factory Design PatternFactory Design Pattern
Factory Design Pattern
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
Factory Method Pattern
Factory Method PatternFactory Method Pattern
Factory Method Pattern
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 
Observer and Decorator Pattern
Observer and Decorator PatternObserver and Decorator Pattern
Observer and Decorator Pattern
 
CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)CLTL python course: Object Oriented Programming (2/3)
CLTL python course: Object Oriented Programming (2/3)
 
Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder Desing pattern prototype-Factory Method, Prototype and Builder
Desing pattern prototype-Factory Method, Prototype and Builder
 
Design Pattern - Factory Method Pattern
Design Pattern - Factory Method PatternDesign Pattern - Factory Method Pattern
Design Pattern - Factory Method Pattern
 
Abstract Factory Pattern
Abstract Factory PatternAbstract Factory Pattern
Abstract Factory Pattern
 
The Factory of the Future - Exponential View SF Dec, 2 2016
The Factory of the Future - Exponential View SF Dec, 2 2016The Factory of the Future - Exponential View SF Dec, 2 2016
The Factory of the Future - Exponential View SF Dec, 2 2016
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Design Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The WorldDesign Patterns For 70% Of Programmers In The World
Design Patterns For 70% Of Programmers In The World
 
Software Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill SparksSoftware Design Patterns in Laravel by Phill Sparks
Software Design Patterns in Laravel by Phill Sparks
 
The factory of the future is here
The factory of the future is hereThe factory of the future is here
The factory of the future is here
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Principles of Design - Graphic Design Theory
Principles of Design - Graphic Design TheoryPrinciples of Design - Graphic Design Theory
Principles of Design - Graphic Design Theory
 
Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 

Similar to Factory and Abstract Factory

The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScript
Tim Perry
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
lhkslkdh89009
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
Lei Kang
 

Similar to Factory and Abstract Factory (20)

Scala101, first steps with Scala
Scala101, first steps with ScalaScala101, first steps with Scala
Scala101, first steps with Scala
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Factory Pattern
Factory PatternFactory Pattern
Factory Pattern
 
How to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescriptHow to build to do app using vue composition api and vuex 4 with typescript
How to build to do app using vue composition api and vuex 4 with typescript
 
Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop Greach 2014 Sesamestreet Grails2 Workshop
Greach 2014 Sesamestreet Grails2 Workshop
 
Laravel Design Patterns
Laravel Design PatternsLaravel Design Patterns
Laravel Design Patterns
 
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
Data Loading Made Easy with Mike Nakhimovich DroidCon Italy 2017
 
The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScript
 
Scala, just a better java?
Scala, just a better java?Scala, just a better java?
Scala, just a better java?
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
Intro
IntroIntro
Intro
 
My Notes from https://www.codeschool.com/courses/git-real
My Notes from  https://www.codeschool.com/courses/git-realMy Notes from  https://www.codeschool.com/courses/git-real
My Notes from https://www.codeschool.com/courses/git-real
 
Decorator design pattern
Decorator design patternDecorator design pattern
Decorator design pattern
 
TYPO3 create a CKEditor plugin
TYPO3 create a CKEditor pluginTYPO3 create a CKEditor plugin
TYPO3 create a CKEditor plugin
 
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
2017 - TYPO3 CertiFUNcation: Frans-Saris - TYPO3 create CKeditor plugin
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
 
Puppeteer - A web scraping & UI Testing Tool
Puppeteer - A web scraping & UI Testing ToolPuppeteer - A web scraping & UI Testing Tool
Puppeteer - A web scraping & UI Testing Tool
 
Testing of javacript
Testing of javacriptTesting of javacript
Testing of javacript
 
Something old, Something new.pdf
Something old, Something new.pdfSomething old, Something new.pdf
Something old, Something new.pdf
 
Building user interface with react
Building user interface with reactBuilding user interface with react
Building user interface with react
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

Factory and Abstract Factory

  • 1. Design Patterns 05/28/10 Week 3: Factory Method and Abstract Factory Jonathan Simon [email_address]
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Technical Debt 05/28/10 Source: http://martinfowler.com/bliki/TechnicalDebtQuadrant.html
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.

Editor's Notes

  1. 13 November 2008
  2. 13 November 2008
  3. 13 November 2008
  4. Singleton Template Strategy 13 November 2008
  5. 13 November 2008
  6. 13 November 2008
  7. Remove the abstract keyword 13 November 2008
  8. 13 November 2008