Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation.

Slides:



Advertisements
Similar presentations
Creational Patterns, Abstract Factory, Builder Billy Bennett June 11, 2009.
Advertisements

Matt Klein. Decorator Pattern  Intent  Attach Additional responsibilities to an object by dynamically. Decorators provide a flexible alternative to.
DESIGN PATTERNS OZGUR RAHMI DONMEZ.
Plab – Tirgul 12 Design Patterns
Prototype8-1 Prototype CS490 Design Patterns Alex Lo, Rose-Hulman Institute May 13, 2003.
Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.
Software Design & Documentation – Design Pattern: Command Design Pattern: Command Christopher Lacey September 15, 2003.
Prototype Pattern Intent:
Design Patterns Based on Design Patterns. Elements of Reusable Object-Oriented Software. by E.Gamma, R. Helm, R. Johnson,J. Vlissides.
Dept. of Computer Engineering, Amir-Kabir University 1 Design Patterns Dr. Noorhosseini Lecture 2.
The Composite Pattern.. Composite Pattern Intent –Compose objects into tree structures to represent part-whole hierarchies. –Composite lets clients treat.
Design Patterns Module Name - Object Oriented Modeling By Archana Munnangi S R Kumar Utkarsh Batwal ( ) ( ) ( )
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VI Composite, Iterator, and Visitor Patterns.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Creational Patterns Making Objects The Smart Way Brent Ramerth Abstract Factory, Builder.
Type Laundering & Prototype Pattern Kunal Chaudhary.
Design Patterns.
CS 4240: Bridge and Abstract Factory Readings:  Chap. 10 and 11 Readings:  Chap. 10 and 11.
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.
Design Pattern. The Observer Pattern The Observer Pattern defines a one-to-many dependency between objects so that when one object changes state, all.
Tech Talk Go4 Factory Patterns Presented By: Matt Wilson.
Creational Patterns CSE301 University of Sunderland Harry R Erwin, PhD.
SOFTWARE DESIGN AND ARCHITECTURE LECTURE 27. Review UML dynamic view – State Diagrams.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns IX Interpreter, Mediator, Template Method recap.
CS 210 Adapter Pattern October 19 th, Adapters in real life Page 236 – Head First Design Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns V More Structural Patterns.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Design Patterns VIII Chain of Responsibility, Strategy, State.
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.
Prototype pattern Participants Prototype (Graphic) – declared an interface for cloning itself ConcretePrototype (EditBox, Slider) – implements an operation.
DESIGN PATTERNS COMMONLY USED PATTERNS What is a design pattern ? Defining certain rules to tackle a particular kind of problem in software development.
Software Design Patterns Curtsy: Fahad Hassan (TxLabs)
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.
Design Patterns Software Engineering CS 561. Last Time Introduced design patterns Abstraction-Occurrence General Hierarchy Player-Role.
Advanced Object-oriented Design Patterns Creational Design Patterns.
The Prototype Pattern (Creational) ©SoftMoore ConsultingSlide 1.
CS 210 Proxy Pattern Nov 16 th, RMI – A quick review A simple, easy to understand tutorial is located here:
Reference – Object Oriented Software Development Using Java - Jia COP 3331 Object Oriented Analysis and Design Chapter 10 – Patterns Jean Muhammad.
Five Minute Design Patterns Doug Marttila Forest and the Trees May 30, 2009 Template Factory Singleton Iterator Adapter Façade Observer Command Strategy.
Overview of Creational Patterns ©SoftMoore ConsultingSlide 1.
An object's behavior depends on its current state. Operations have large, multipart conditional statements that depend on the object's state.
PROTOTYPE. Design Pattern Space Purpose ScopeCreationalStructuralBehavioral ClassFactory MethodAdapterInterpreter Template Method ObjectAbstract factory.
Design Patterns Creational Patterns. Abstract the instantiation process Help make the system independent of how its objects are created, composed and.
COMPOSITE PATTERN NOTES. The Composite pattern l Intent Compose objects into tree structures to represent whole-part hierarchies. Composite lets clients.
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.
Design Patterns: MORE Examples
Abstract Factory Pattern
Factory Method Pattern
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Linzhang Wang Dept. of Computer Sci&Tech, Nanjing University
Factory Patterns 1.
Introduction to Design Patterns
Behavioral Design Patterns
object oriented Principles of software design
Abstract Factory Pattern
Intent (Thanks to Jim Fawcett for the slides)
Software Engineering Lecture 7 - Design Patterns
Object Oriented Design Patterns - Creational Patterns
Decorator Pattern Richard Gesick.
Prototype Pattern 1.
Ms Munawar Khatoon IV Year I Sem Computer Science Engineering
CS 350 – Software Design Principles and Strategies – Chapter 14
Lesson 5: More on Creational Patterns
Creational Patterns.
Strategy Pattern Jim Fawcett CSE776 – Design Patterns Fall 2014.
Presentation transcript:

Prototype Creational Design Pattern By Brian Cavanaugh September 22, 2003 Software, Design and Documentation

Creational Patterns ► Design patterns of this nature are an abstraction of the instantiation process. ► These encapsulate knowledge about which concrete classes the system uses. ► These patterns also hides how instances of these classes are created and put together. ► This adds up to huge flexibility on what, who, how and when “stuff” gets created.

What is a Prototype Design Pattern? ► This type of pattern uses classes and other objects as a prototypical instances, and then create objects by copying these prototypical instances – the prototypes – and using them to create the instantiated instances.

So how does Prototype fit in? ► If a function is parameterized by various prototypical classes, which it then copies and adds to the program, then you can change the program’s running composition by replacing the prototypical objects with different ones. You’re using prototypes! ► Lost because of words? Well, here come the pictures! ^_^

Photoshop Possible Programming ► This is one of the toolbars in Photoshop. Let’s say each button is an object of class “GraphicTool” and each of the jobs that these objects do can be described of “DrawingStuff”

Tool manipulate() RotateTool manipulate() GraphicTool manipulate() createGraphic() g = createGraphic() while (user drags mouse) { g->draw(new position) } insert g into drawing Pencil createGraphic() Erase createGraphic() DrawingStuff manipulate() createGraphic() Prototype …… UML Diagram …… Returns copy of self

Prototype Class Diagram Client operation() Prototype clone() ConcreteProto1 clone() ConcreteProto2 clone() prototype return copy of self p = prototype->clone() Graphic from Client – creates a new object by asking a prototype to clone itself. Prototype – declares an interface for cloning itself! Concrete Prototypes – implements an operation for cloning itself These describe the Participants

Consequences of Prototype ► Overall – this hides the concrete product classes from the client, thereby reducing the number of names clients know about. Moreover, this DP allows the client work with application-specific classes without modification. ► This SCREAMS of code re-usage – you could even use the “Tool” class (from Photoshop) for different types of programs – Like music writing software – and drawing stuff would then be “Notes”, “Clefs” or another concrete class!

Additional Benefits ► Adding and removing products at Run Time ► Specifying new objects by varying values ► Specifying new objects by varying structure ► Reduced Subclassing ► Configuring an application with classes dynamically

There’s a catch, right? ► Unfortunately, yes. ► The Clone() operation can be VERY complicated. This brings us to implementation…

Implementation of Prototype ► Using a prototype manager  Basically, using a registry for the prototypes. ► Implementing the Clone operation…  This is REALLY tricky when you have objects with Circular references.  Most languages provide shallow copies – they share some information from the original. Usually, you NEED a Deep copy – nothing shared! If your object has Save & Load operations, this is a lot easier to implement.

Implementation (cont) ► Initialize clones  Are we seeing a recurrence of the “Clones aren’t easy” idea – yep  You may have to create an Initialize function for your clones because clients may want to initialize some, if not all of the internal state values, and you typically can’t pass values into the “Clone” operation because Clone varies from object to object, and is inherited from the prototype class.

So…when should you use Prototype? ► Should use this when a system should be independent of how its products are created, composed and represented and one or more of the following:  When the classes to instantiate are specified at Run-Time  To avoid building a class hierarchy that’s really deep  When instances of a class have few differences

How does Prototype relate? ► Closely related to the other Creational Design Patterns. Many times, you can use these patterns together. ► Of the creational DP’s, it’s most competitive/similar to Abstract Factory. ► Also, designs that use the Composite and Decorator Structural Design Patterns often can really benefit from using Prototype.

Overview ► Prototype is used by making copies of concrete classes for objects, using clone(). ► Clone can be hard to code, but allows for huge amounts of flexibility. ► This is similar in idea to Templates, except rather than algorithms, it just creates default types of concrete classes. ► Once you understand Clone, this can save you a lot of work.

Any Questions? "I've been on courses about this: you stand at the front, you maintain eye contact with the students, and you get this wonderful flow of communication with the audience. Bollocks. Those people have never taught a group of Computer Science students." "Um, what was the question?" Tim Hopkins and a random CS2 student