1 / 10

Prototype Pattern

Prototype Pattern. Creational Pattern. Specify the kinds of objects to create using a prototypical instance, and create new objects by copy this prototype. Problem. Problem: The GraphicTool class belongs to the framework, while the graphical classes are

lita
Download Presentation

Prototype Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Prototype Pattern

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

  3. 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.

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

  5. Solution Two

  6. 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.

  7. Applicability The prototype pattern is used when a system should be independent of how its products are created, composed, and represented; and • when the classes to instantiate are specified at run-time; for example, the dynamic loading • 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

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

  9. Implementation • Using a prototype manager. • Implementing the Clone operation. • Initializing clones.

  10. Questions?

More Related