Creational Patterns: The Abstract Factory CSE 335 Spring 2008 E. Kraemer.

Slides:



Advertisements
Similar presentations
Creational Design Patterns. Creational DP: Abstracts the instantiation process Helps make a system independent of how objects are created, composed, represented.
Advertisements

Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
T O K ILL A S INGLETON F ACTORY M ETHOD P ATTERN Josh Mason 6/18/09.
Plab – Tirgul 12 Design Patterns
 Consists of Creational patterns  Each generator pattern has a Client, Product, and Generator.  The Generator needs at least one operation that creates.
. Plab – Tirgul 12 Design Patterns. Design Patterns u The De-Facto Book on Design Patterns:
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Nov, 1, Design Patterns PROBLEM CONTEXT SOLUTION A design pattern documents a proven solution to a recurring problem in a specific context and its.
Prototype Pattern Intent:
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
1 Creational Patterns CS : Software Design Winter /T8.
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
+ Informatics 122 Software Design II Lecture 8 Emily Navarro Duplication of course material for any commercial purpose without the explicit written permission.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
Design Patterns.
Creational Patterns (1) CS350, SE310, Fall, 2010.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
Abstract Factory Design Pattern making abstract things.
Software Components Creational Patterns.
Abstract Factory Abstract Factory using Factory Method.
12/6/20041 The Factory Method Pattern Presenters 王世賀 F 陳祐毓 F 張峻銘 F 吳佩達 F 林俊成 F 鄭榮智 F 許書豪 F
The Factory Patterns SE-2811 Dr. Mark L. Hornick 1.
Creational Patterns CSE Creational Patterns Class creational pattern ◦ uses inheritance to vary the class that is instantiated Object creational.
Factory Method Chris Colasuonno Also known as “Virtual Constructor”
Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method Pattern.
The Factory Method Design Pattern Motivation: Class / Type separation – Abstract class serves as type definition and concrete class provides implementation.
Abstract Factory and Factory Method CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Factory Method Explained. Intent  Define an interface for creating an object, but let subclasses decide which class to instantiate.  Factory Method.
Define an interface for creating an object, but let subclasses decide which class to instantiate.
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
DESIGN PATTERNS Sanjeeb Kumar Nanda 30-Aug What is a pattern? Pattern is a recurring solution to a standard problem Each Pattern describes a problem.
CS 590L – Distributed Component Architecture 02/20/2003Uttara Paingankar1 Design Patterns: Factory Method The factory method defines an interface for creating.
ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory.
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
The Factory Method Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Advanced Object-oriented Design Patterns Creational Design Patterns.
CSC 480 Software Engineering Lab 5 – Abstract Factory Pattern Oct 30, 2002.
Chapter 8 Object Design Reuse and Patterns. More Patterns Abstract Factory: Provide manufacturer independence Builder: Hide a complex creation process.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
 Creational design patterns abstract the instantiation process.  make a system independent of how its objects are created, composed, and represented.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
The Abstract Factory Pattern (Creational) ©SoftMoore ConsultingSlide 1.
S.Ducasse Stéphane Ducasse 1 Abstract Factory.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
Abstract Factory Pattern Jiaxin Wang CSPP Winter 2010.
Abstract Factory pattern Intent Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
SOFTWARE DESIGN Design Patterns 1 6/14/2016Computer Science Department, TUC-N.
Factory Method. Intent/Purpose Factory Method is used to deal with a problem of creating objects without specifying the EXACT class of object that we.
Factory Method Pattern. Admin SCPI Patner Day Feb. 21 Lunch count Presentation (4-8 min.) Practice on Feb. 16. Morning availablity on Feb21 Brief overview.
Design Patterns: MORE Examples
Abstract Factory Pattern
Factory Method Pattern
Design Pattern Catalogues
Factory Patterns 1.
Design Patterns Lecture 1
Software Design and Architecture
Factory Method Pattern
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
CSE 432 Presentation GoF: Factory Method PH: “To Kill a Singleton”
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Creational Patterns.
Informatics 122 Software Design II
Design by Abstraction (Continuation) CS 3331 Spring 2005
Presentation transcript:

Creational Patterns: The Abstract Factory CSE 335 Spring 2008 E. Kraemer

Creational Patterns Abstract instantiation process Makes system independent of how its objects are –created –composed –represented Encapsulates knowledge about which concrete classes the system uses Hides how instances of these classes are created and put together

Abstract Factory Provide an interface for creating families of related or dependent objects without specifying their concrete classes

Example that would benefit from Abstract Factory BuildComputer(ComputerModelA& comp) {comp.Add(new MemoryTypeA); comp.Add(new CPUTypeA); comp.Add(new ModemTypeA); } ComputerModelA MemoryType A CPUTypeAModemTypeA What if I want to build a Computer of Model B with Model B Memory,CPU and Modem?

Using Abstract Factory ComputerFactory createComputer() createMemory() createCPU() createModem() CompFactoryB createComputer() createMemory() createCPU() createModem() CompFactoryA createComputer() createMemory() createCPU() createModem() Computer ModelA Computer ModelB Computer Memory ModelA Memory ModelB Memory Client

BuildComputer(Computer& comp, ComputerFactory& compFactory) { comp.Add(compFactory.createMemory()); comp.Add(compFactory.createCPU()); comp.Add(compFactory.createModem()); } Using Abstract Factory...

When to use Abstract Factory? Use Abstract Factory when: –system should be independent of how its products are created, composed and represented –system should be configured with one of multiple families of products –a family of related product objects must be used together and this constraint need to be enforced –you want to reveal only the interface, and not the implementation, of a class library of products

Structure AbstractFactory createProdA() createProdB() ConcreteFactory1 createProdA() createProdB() ProdA1 ProdA2 Abstract ProductA ProdB1 ProdB2 Abstract ProductB Client ConcreteFactory1 createProdA() createProdB()

Consequences of using Abstract Factory Isolates concrete classes Makes exchanging products families easy Promotes consistency among products Supporting new kinds of products is difficult

Factory Method Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses. Also known as Virtual Constructor

Want to develop a framework of a Computer that has memory, CPU, modem. Actual memory, CPU, and modem used depends on actual computer model Want to provide a configure function that will configure any computer with appropriate parts. This function must be written such that it does not depend on the specifics of a computer model or the components. Example that would benefit from Factory Method

Example using Factory Method Memory MemoryA Computer ComputerA createMemory() createCPU() Configure() Memory* mem =createMemory(); add (mem); CPU* cpu = createCPU(); add(cpu); createMemory() createCPU() return new MemoryA; return new CPUA;

When to use Factory Method? A class can’t anticipate the class of objects it must create a class wants its subclasses to specify the objects it creates classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate

Structure Product concreateProduct Creator ConcreteCreator FactoryMethod() anoperation() Product = FactoryMethod(); FactoryMethod return newConcreateProduct;

Consequences of using Factory Method Provides hooks for subclasses Connects parallel class hierarchies

Factory Method Vs. Other Pattern Abstract Factory often implemented with Factory Method Factory Methods usually called within Template Methods Prototypes don’t require subclassing the Creator. However, they often require initialize operation on the Product class. Factory Method doesn’t require such an operation Proliferation of subclasses