Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.

Slides:



Advertisements
Similar presentations
Chain of Responsibility Pattern Gof pp Yuyang Chen.
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
Prototype8-1 Prototype CS490 Design Patterns Alex Lo, Rose-Hulman Institute May 13, 2003.
Flyweight An Object Structural Design Pattern JM Imbrescia.
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:
FrameworksFrameworks chap8. Framework Set of cooperating classes Structures the essential mechanisms of a problem domain Framework != design pattern Typical.
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
1 Creational Patterns CS : Software Design Winter /T8.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.
1 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
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.
Composite Design Pattern. Motivation – Dynamic Structure.
Type Laundering & Prototype Pattern Kunal Chaudhary.
Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns II.
Software Components Creational Patterns.
GoF: Document Editor Example Rebecca Miller-Webster.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
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.
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.
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.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University The Strategy Pattern.
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.
1 Prototype Design Pattern Nitin Prabhu Adapted from presentations of Mike Fortozo,John Lin
Billy Bennett June 22,  Intent Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
Interfaces About Interfaces Interfaces and abstract classes provide more structured way to separate interface from implementation
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
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 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.
CLASSIFICATION OF DESIGN PATTERNS Hladchuk Maksym.
Command Pattern. Intent encapsulate a request as an object  can parameterize clients with different requests, queue or log requests, support undoable.
Generator Design Patterns: Singleton and Prototype
Design Patterns: MORE Examples
Abstract Factory Pattern
Factory Method Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Factory Patterns 1.
Creational Pattern: Prototype
Software Design and Architecture
Software Design and Architecture
Design Patterns with C# (and Food!)
Factory Method Pattern
object oriented Principles of software design
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Design Patterns - A few examples
Design Patterns Satya Puvvada Satya Puvvada.
Object Oriented Design Patterns - Creational Patterns
UNIT-III Creational Patterns UNIT-III.
Prototype Pattern 1.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
Strategy Design Pattern
Lesson 5: More on Creational Patterns
Creational Patterns.
Decorator Pattern.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation for cloning itself Client (GraphicTool) – creates a new object by asking a prototype to clone itself

Prototype Motivation

Prototype pattern Motivation Tool Manipulate() RotateTool Manipulate() p = prototype->Clone() while (user drags mouse) { p->Draw(new position) } insert p into drawing prototype GraphicTool Manipulate() Graphic Draw(position) Clone() EditBox Draw(position) Clone() Slider Draw(position) Clone() return copy of self

Prototype Structure Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.

Prototype pattern Structure p = prototype->Clone() Prototype Clone() prototype Client Operation() ConcretePrototype1 Clone() ConcretePrototype Clone() return copy of self

Prototype pattern Applicability Use the Prototype pattern when a system should be independent of how its products are created, composed, and represented; Where the system should be highly dynamic, and – when the classes to instantiate are specified at run-time; or – to avoid building a class hierarchy of factories that parallels the class hierarchy of products; or – when instances of a class can have one of only a few different combinations of state. It may be convenient to install a corresponding number of prototypes and clone them rather than instatiating the class manually, each time with an appropriate state

Consequences Adding and removing prototypes at run-time Specifying new prototypes by varying values – define new behavior through object composition - by specifying values for an objects variables - and not by defining a new class – Specifying new prototypes by varying the structure – Example: editors for circuit design; build a circuit out of sub- circuit Reduced subclassing – Prototype pattern can be used instead of Factory Method pattern to avoid building parallel hierarchies of creators and products – no need of creator hierarchy at all – Benefits for C++ realization Configuring application with subclasses dynamically

Implementation Using a prototype manager – when number of prototypes in the system is not fixed; – to keep a registry of available prototypes; – prototype manager is an associative store that returns the prototype matching the given key Implementing the Clone operation – “shallow copy versus deep copy” Initializing clones – need to initialize cloned object to values specified by client – can’t pass this values to Clone(), because their number will vary between classes of prototypes – define separate Initialize(…) operation to set clone’s internal state for each prototype class accordingly