 Creational design patterns abstract the instantiation process.  make a system independent of how its objects are created, composed, and represented.

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 (2) CS350/SE310 Fall, Lower the Cost of Maintenance Economic Goal Coupling-Cohesion, Open-Close, Information-Hiding, Dependency.
Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Copyright © Active Frameworks Inc. - All Rights Reserved - V2.0Creational Patterns - Page L4-1 PS95&96-MEF-L11-1 Dr. M.E. Fayad Creationa l Paradigm.
Design Patterns CS 406 Software Engineering I Fall 2001 Aditya P. Mathur Purdue University October 30, 2001.
Overview of Design Patterns
Slides by Alex Mariakakis with material from David Mailhot, Hal Perkins, Mike Ernst Section 9: Design Patterns.
CSE3308/CSC Software Engineering: Analysis and DesignLecture 5B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/CSC3080/DMS/2000/12.
Plab – Tirgul 12 Design Patterns
Creational PatternsCmpE1961 Creational Patterns Patterns used to abstract the process of instantiating objects. –class-scoped patterns uses inheritance.
CSE Software Engineering: Analysis and Design, 2002Lecture 7B.1 Software Engineering: Analysis and Design - CSE3308 Patterns CSE3308/DMS/2002/15.
© O. Nierstrasz, O. Greevy, A. Kuhn P2 — Clients and Servers 8.1 Roadmap  Generics  Abstract Factory  Annotations  Model-Driven Engineering.
Based on slides of: Mira Balaban Department of Computer Science Ben-Gurion university F. Tip. IBM T J Watson Research Center. Creational Patterns Software.
OOMPA Lecture 10 Design Patterns Singleton Factory Method
Prototype Pattern Intent:
Design Patterns David Talby. This Lecture n The Creational Patterns u Abstract Factory u Builder u Prototype u Factory Method n Choosing Between Them.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Softwaretechnologie für Fortgeschrittene Teil Thaller Stunde V: Software Engineering II Köln 28. Januar 2010.
1 Creational Patterns CS : Software Design Winter /T8.
Design Patterns Examples in C++ Moshe Fresko Bar-Ilan University Object Oriented Programming
Creational Patterns: The Abstract Factory CSE 335 Spring 2008 E. Kraemer.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Pattern Abstract Factory
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
ECE450S – Software Engineering II Creational Design Patterns.
Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns II.
Case Studies on Design Patterns Design Refinements Examples.
Creational Patterns (1) CS350, SE310, Fall, 2010.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
Software Components Creational Patterns.
Beware of bugs in the above code; I have only proved it correct, not tried it.
Abstract Factory Abstract Factory using Factory Method.
Creational Patterns CSE Creational Patterns Class creational pattern ◦ uses inheritance to vary the class that is instantiated Object creational.
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.
OO Methodology Elaboration Iteration 2 - Design Patterns -
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.
FACTORY METHOD. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract.
ANU COMP2110 Software Design in 2004 Lecture 17Slide 1 COMP2110 in 2004 Software Design Lecture 17: Software design patterns (4) 1The Abstract Factory.
Java Design Patterns Java Design Patterns. What are design patterns? the best solution for a recurring problem a technique for making code more flexible.
Religious Studies 313 – Advanced Programming Topics.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns I.
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.
07 - Creational (3)CSC4071 Builder Separate the construction of a complex object from its representation so that the same construction process can create.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
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.
07 - Creational PatternsCSC4071 Creational Patterns Patterns used to abstract the process of instantiating objects. –class-scoped patterns uses inheritance.
Creational Patterns C h a p t e r 3 – P a g e 14 Creational Patterns Design patterns that deal with object creation mechanisms and class instantiation,
Overview of Design Patterns
Design Pattern.
Abstract Factory Pattern
Factory Patterns 1.
Abstract Factory Pattern
Section 9: Design Patterns
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Design Patterns Difficult to describe abstractly Elements:
Creational Patterns.
Software Design Lecture 9.
Presentation transcript:

 Creational design patterns abstract the instantiation process.  make a system independent of how its objects are created, composed, and represented. Main goal is: Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

AbstractFactory (WidgetFactory) declares an interface for operations that create abstract product objects. ConcreteFactory (Motif & PMWidgetFactory) implements the operations to create concrete product objects.

AbstractProduct (Window, ScrollBar) declares an interface for a type of product object. ConcreteProduct (MotifWindow, MotifScrollBar) 1- defines a product object to be created by the corresponding concrete factory. 2-implements the AbstractProduct interface. Client uses only the interfaces declared by AbstractFactory and AbstractProduct

 a system should be independent of how its products are created.  a system should be configured with one of multiple families of products.  a family of related product objects is designed to be used together, and you need to enforce this constraint.  you want to provide a class library of products, and you want to reveal just their interfaces, not their implementations.

 It isolates concrete classes. ◦ It isolates clients from implementation classes. Clients manipulate instances through their abstract interfaces.  It makes exchanging product families easy. ◦ It can use different product configurations simple by changing the concrete factory.

 It promotes consistency among products ◦ To enforce that an application use objects from only one family at a time.  Supporting new kinds of products is difficult  Adding a new product requires extending the abstract interface which implies that all of its derived concrete classes also must change.  Essentially everything must change to support and use the new product family  abstract factory interface is extended  derived concrete factories must implement the extensions  a new abstract product class is added  a new product implementation is added  client has to be extended to use the new product

 Abstract Factory pattern to creating mazes class MazeFactory { public: MazeFactory(); virtual Maze * MakeMaze() const; virtual Wall * MakeWall() const; virtual Room * MakeRoom(int n) const; virtual Door* MakeDoor(Room *r1, Room* r2) const; }

 CreateMaze taking a MazeFactory as a parameter Maze *MazeGame::CreateMaze(MazeFactory& factory) { Maze * aMaze = factory.MakeMaze(); Room * r1 = factory.MakeRoom(1); Room *r2 = factory.MakeRoom(2); … }

 EnhantedMazeFactory class EnchantedMazeFactory: public MazeFactory { public: EnchantedMazeFactory(); virtual Room* MakeRoom(int n) const {return new EnchantedRoom(n, CastSpell());} virtual Door* MakeDoor(Room *r1, Room* r2) const {return new DoorNeedingSpell(r1,r2);} protected:Spell* CastSpell() const; }

 BombedMazeFactory Wall * BombedMazeFactory::MakeWall() const { return new BombedWall; } Room *BombedMazeFactory::MakeRoom(int n) const { return new RoomWithABomb(n); }

 Code using BombedMazeFactory MazeGame game; BombedMazeFactory factory; game.CreateMaze(factory);  CreateMaze can take an instance of EnchantedMazeFactory just as well to build enchanted mazes.

interface GUIFactory { public Button createButton(); } class WinFactory implements GUIFactory { public Button createButton() { return new WinButton(); } } class OSXFactory implements GUIFactory { public Button createButton() { return new OSXButton(); } }

interface Button { public void paint(); } class WinButton implements Button { public void paint() { System.out.println("I'm a WinButton"); } class OSXButton implements Button { public void paint() { System.out.println("I'm an OSXButton"); }

class Application { public Application(GUIFactory factory) { Button button = factory.createButton(); button.paint(); } public class ApplicationRunner { public static void main(String[] args) { new Application(createOsSpecificFactory()); } public static GUIFactory createOsSpecificFactory() { int sys = readFromConfigFile("OS_TYPE"); if (sys == 0) { return new WinFactory(); } else { return new OSXFactory(); } }