Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.

Similar presentations


Presentation on theme: "Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype."— Presentation transcript:

1

2 Prototype Pattern

3 Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype.

4 Problem Problem: The GraphicTool class belongs to the framework, while the graphical classes are application-specific, so the GraphicTool class doesn't know how to create graphical objects and then operate on them.

5 Solution One This method will produce many subclasses that are different only in the kind of music objects they instantiated.

6 Solution Two

7 Structure Participants Prototype(Graphic) - -declares an interface for cloning itself. ConcretePrototype (Staff,WholeNote, HalfNote) - -implements an operation for cloning itself. Client(GraphicalTool) - creates a new object by asking a prototype to clone itself.

8 Applicability The prototype pattern is used when a system should be independent of how its products are created, composed, and represented; and 1.when the classes to instantiate are specified at run-time; for example, the dynamic loading 2.to avoid building a class hierarchy of factories that parallels the class hierarchy of products; or 3.when instances of a class can have one of only a few different combinations of state

9 Consequences 1.Isolating concrete product classes from the client. 2.Dynamically adding and removing products at run-time. 3.Specifying new objects by varying values. 4.Specifying new objects by varying structure. 5.Reducing the need for sub-classing. 6.Configuring an application with classes dynamically. 7.Main liability: Clone() needed.

10 Implementation 1.Using a prototype manager. 2.Implementing the Clone operation. 3.Initializing clones.

11 Questions?


Download ppt "Prototype Pattern Creational Pattern Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype."

Similar presentations


Ads by Google