Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.

Slides:



Advertisements
Similar presentations
Creational Patterns (2) CS350/SE310 Fall, Lower the Cost of Maintenance Economic Goal Coupling-Cohesion, Open-Close, Information-Hiding, Dependency.
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.
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
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.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
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.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Abstract Factory Pattern.
Pattern Abstract Factory
Builder A Creational Design Pattern A Presentation by Alex Bluhm And.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. The Factory Method Design Pattern (1) –A creational design.
Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns II.
Case Studies on Design Patterns Design Refinements Examples.
An Introduction to Design Patterns. Introduction Promote reuse. Use the experiences of software developers. A shared library/lingo used by developers.
Abstract Factory Design Pattern making abstract things.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
Software Components Creational Patterns.
Abstract Factory Abstract Factory using Factory Method.
Unit 4 Object-Oriented Design Patterns NameStudent Number CAI XIANGHT082182A KYAW THU LINHT082238Y LI PENGFEIHT082220L NAUNG NAUNG LATTHT082195L PLATHOTTAM.
CDP-1 9. Creational Pattern. CDP-2 Creational Patterns Abstracts instantiation process Makes system independent of how its objects are –created –composed.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
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.
The Builder pattern Shuanghui Luo. Type & intent One of the Creational PatternOne of the Creational Pattern Intent:Intent:  Separates the construction.
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.
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.
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.
Design Pattern : Builder SPARCS 04 고윤정. Main Concepts One of Creational Patterns. Process to construct Complex object in Abstract type. –Use the same.
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,
Builder Introduction. Intent Separate the construction of a complex object from its representation so that the same construction process can create different.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Design Patterns: MORE Examples
Abstract Factory Pattern
Design Pattern Catalogues
Design Patterns Lecture part 2.
Factory Patterns 1.
Software Design and Architecture
Design Patterns with C# (and Food!)
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
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Lesson 5: More on Creational Patterns
Creational Patterns.
Informatics 122 Software Design II
Presented by Igor Ivković
Presentation transcript:

Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder

What are creational patterns? Design patterns that deal with object creation mechanisms, trying to create objects in a manner suitable to the situation Make a system independent of the way in which objects are created, composed and represented Recurring themes: –Encapsulate knowledge about which concrete classes the system uses (so we can change them easily later) –Hide how instances of these classes are created and put together (so we can change it easily later)

Benefits of creational patterns Creational patterns let you program to an interface defined by an abstract class That lets you configure a system with “product” objects that vary widely in structure and functionality Example: GUI systems –InterViews GUI class library –Multiple look-and-feels –Abstract Factories for different screen components

Benefits of creational patterns Generic instantiation – Objects are instantiated without having to identify a specific class type in client code (Abstract Factory, Factory) Simplicity – Make instantiation easier: callers do not have to write long complex code to instantiate and set up an object (Builder, Prototype pattern) Creation constraints – Creational patterns can put bounds on who can create objects, how they are created, and when they are created

Abstract Factory: An Example PIM system Manage addresses and phone numbers –You hard-coded it for US data –At some point, you wanted to extend it to incorporate any address / phone number –So you subclassed DutchAddress, JapanesePhoneNumber, etc. –But now, how do you create them?

Abstract Factory: Overview Intent –Provide an interface for creating families of related or dependent objects without specifying their concrete classes Analogous to a pasta maker Your code is the pasta maker Different disks create different pasta shapes: these are the factories All disks have certain properties in common so that they will work with the pasta maker All pastas have certain characteristics in common that are inherited from the generic “Pasta” object

Abstract Factory: Participants AbstractFactory Declares an interface for operations that create abstract products ConcreteFactory Implements the operations to create concrete product objects: usually instantiated as a Singleton AbstractProduct Declares an interface for a type of product object; Concrete Factories produce the concrete products ConcreteProduct Defines a product object to be created by the corresponding concrete factory

Abstract Factory: Applicability Use 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 –You want to provide a class library of products, and you want to reveal just their interfaces, not their implementations

Abstract Factory: Consequences Good: –Isolates concrete classes All manipulation on client-side done through abstract interfaces –Makes exchanging product families easy Just change the ConcreteFactory –Enforces consistency among products Bad –Supporting new kinds of products is difficult –Have to reprogram Abstract Factory and all subclasses –But it’s not so bad in dynamically typed languages

Abstract Factory: Implementation Usually should be a Singleton Define a Factory Method (GoF) in AbstractFactory – ConcreteFactory then specifies its products by overriding the factory for each public class USAddressFactory implements AddressFactory{ public Address createAddress(){ return new USAddress(); } public PhoneNumber createPhoneNumber(){ return new USPhoneNumber(); } Maybe use Prototype pattern in dynamically typed languages (e.g. Smalltalk) to simplify creation

Builder: Overview Intent –Separate the construction of a complex object from its representation so that the same construction process can create different representations Think of a car factory –Boss tells workers (or robots) to build each part of a car –Workers build each part and add them to the car being constructed

Builder: Participants Builder Specifies an abstract interface for creating parts of a Product object ConcreteBuilder Constructs and assembles parts of the product by implementing the Builder interface Director Constructs an object using the Builder interface Product Represents the complex object under construction Includes classes that define the constituent parts Gives interfaces for assem- bling the parts

Builder: Collaborations Client creates Director object and configures it with a Builder Director notifies Builder to build each part of the product Builder handles requests from Director and adds parts to the product Client retrieves product from the Builder

Builder: Applicability Use Builder 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 being constructed –The building process can be broken down into discrete steps (difference between Builder and Abstract Factory)

Builder: Consequences Lets you vary a product’s internal representation by using different Builders Isolates code for construction and representation Gives finer-grain control over the construction process

Builder: Implementation Issues to consider: –Assembly and construction interface: generality –Is an abstract class for all Products necessary? Usually products don’t have a common interface –Usually there’s an abstract Builder class that defines an operation for each component that a director may ask it to create. These operations do nothing by default (empty, non- virtual methods in C++) The ConcreteBuilder overrides operations selectively

Conclusions Creational design patterns are beneficial in that they allow your software to tightly control the way in which it constructs objects Separate users of the code from the messy details of creating and building objects

Conclusions Abstract Factory: –Lets you choose what family of products to create at runtime –Isolates the implementation from clients, since clients only use the interfaces –Makes exchanging product families simple

Conclusions Builder: –Lets you vary how a product gets assembled. –Can define a new kind of builder for a product to assemble it in a different way –Client doesn’t need to know anything about the construction process, nor the parts that make up a product.

Questions?