Prototype Pattern - PowerPoint PPT Presentation

About This Presentation
Title:

Prototype Pattern

Description:

implements an operation for cloning itself. Client(GraphicalTool) - creates a new object by asking a prototype to clone itself. Applicability ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 11
Provided by: Jess294
Category:

less

Transcript and Presenter's Notes

Title: Prototype Pattern


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

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

10
Questions?
Write a Comment
User Comments (0)
About PowerShow.com