Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.

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.
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.
Plab – Tirgul 12 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.
Design Pattern Course Builder Pattern 1 Mahdieh Monzavi AmirKabir University of Technology, Department of Computer Engineering & Information Technology.
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.
Creational Patterns: The Abstract Factory CSE 335 Spring 2008 E. Kraemer.
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
ECE 355 Design Patterns Tutorial Part 2 (based on slides by Ali Razavi) Presented by Igor Ivković
Design Patterns academy.zariba.com 1. Lecture Content 1.What are Design Patterns? 2.Creational 3.Structural 4.Behavioral 5.Architectural 6.Design Patterns.
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.
Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns II.
Creational Patterns (1) CS350, SE310, Fall, 2010.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
02 - Creational Design Patterns Moshe Fresko Bar-Ilan University תשס"ח 2008.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Components Creational Patterns.
Abstract Factory Abstract Factory using Factory Method.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Design Patterns CS 124 Reference: Gamma et al (“Gang-of-4”), Design Patterns.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
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.
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.
Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.
Builder An Object Creational Pattern Tim Rice CSPP51023 March 2, 2010.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Design Pattern. Definition: A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
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.
Advanced Object-oriented Design Patterns Creational Design Patterns.
CSC 480 Software Engineering Lab 5 – Abstract Factory Pattern Oct 30, 2002.
Singleton Pattern Presented By:- Navaneet Kumar ise
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.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
S.Ducasse Stéphane Ducasse 1 Abstract Factory.
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.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
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,
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Pattern Catalogues
Design Patterns Lecture part 2.
Factory Patterns 1.
Software Design and Architecture
object oriented Principles of software design
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Presented by Igor Ivković
Design Patterns - A few examples
Software Engineering Lecture 7 - Design Patterns
Abstract Factory Pattern
Informatics 122 Software Design II
Object Oriented Design Patterns - Creational Patterns
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Creational Patterns.
Informatics 122 Software Design II
Presented by Igor Ivković
Presentation transcript:

Design Patterns Creational Patterns

Abstract the instantiation process Help make the system independent of how its objects are created, composed and represented 5 design patterns Abstract the instantiation process Help make the system independent of how its objects are created, composed and represented 5 design patterns

Abstract Factory Intent –Provide an interface for creating families of related or dependent objects without specifying their concrete classes Also Known As –Kit Motivation –Write a toolkit to allow applications with GUI interfaces to run on multiple platforms (Mac, PC, OS/2, Unix motif ) Intent –Provide an interface for creating families of related or dependent objects without specifying their concrete classes Also Known As –Kit Motivation –Write a toolkit to allow applications with GUI interfaces to run on multiple platforms (Mac, PC, OS/2, Unix motif )

Applicability –use the Abstract Factory when: a system should be independent of how its products are created, composed and represented 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 implementation Applicability –use the Abstract Factory when: a system should be independent of how its products are created, composed and represented 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 implementation

Structure

Participants –AbstractFactory - declares an interface for operations that create abstract products –ConcreteFactory - implements the operations to create concrete product objects –AbstractProduct - declares an interface for a type of product object –Product - defines a product object to be created by the corresponding concrete factory, implements the AbstractProduct interface –Client - uses interfaces declared by AbstractFactory and AbstractProduct classes Participants –AbstractFactory - declares an interface for operations that create abstract products –ConcreteFactory - implements the operations to create concrete product objects –AbstractProduct - declares an interface for a type of product object –Product - defines a product object to be created by the corresponding concrete factory, implements the AbstractProduct interface –Client - uses interfaces declared by AbstractFactory and AbstractProduct classes

Collaborations –Normally a single instance of a ConcreteFactory class is created at run-time –This concrete factory creates product objects having a particular implementation –To create different product objects, clients should use a different concrete factory Consequences –It isolates concrete classes –It makes exchanging product families easy –It promotes consistency among products –Supporting new kinds of products is difficult Collaborations –Normally a single instance of a ConcreteFactory class is created at run-time –This concrete factory creates product objects having a particular implementation –To create different product objects, clients should use a different concrete factory Consequences –It isolates concrete classes –It makes exchanging product families easy –It promotes consistency among products –Supporting new kinds of products is difficult

Implementation & sample code abstract classes inheritance see code.... abstract classes inheritance see code....

Builder Separate the construction of a complex object from its representation so that the same construction process can create different representations Use the Builder pattern when: –the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled –the construction process must allow different representations for the object that's constructed Separate the construction of a complex object from its representation so that the same construction process can create different representations Use the Builder pattern when: –the algorithm for creating a complex object should be independent of the parts that make up the object and how they're assembled –the construction process must allow different representations for the object that's constructed

Factory Method Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method is similar to Abstract Factory but without the emphasis on families Define an interface for creating an object, but let subclasses decide which class to instantiate Factory Method is similar to Abstract Factory but without the emphasis on families

Factory Method

Prototype Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype Use the Prototype pattern: –when the classes to instantiate are specified at run- time –to avoid building a class hierarchy of factories that parallels the class hierarchy of products –when instances of a class can have one of only a few different combinations of state. It may be easier to have the proper number of prototypes and clone them rather than instantiating the class manually each time Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype Use the Prototype pattern: –when the classes to instantiate are specified at run- time –to avoid building a class hierarchy of factories that parallels the class hierarchy of products –when instances of a class can have one of only a few different combinations of state. It may be easier to have the proper number of prototypes and clone them rather than instantiating the class manually each time

Prototype

Singleton We want to have only one instance of an object in the system Examples: –Printer Spooler –Window Manager We want to have only one instance of an object in the system Examples: –Printer Spooler –Window Manager

Solution 1 - Global Variable external DB* theDB; DB* theDB; int main() { theDB = new DB(); //… } db.h db.cpp main.cpp

Problems How do we make sure only one instance exists ? What if one global is using another ? What if we want to have 0..4 instances alive ? How do we make sure only one instance exists ? What if one global is using another ? What if we want to have 0..4 instances alive ?

The solution: A Singleton!