Prototype Pattern

  • 1,282 views
Uploaded on

For Design Pattern Class Presentation

For Design Pattern Class Presentation

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,282
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
33
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Prototype pattern
    Yu Chen &Ider Zheng
    CSE 776 - Design Patterns by Jim Fawcett
    Fall 2011
  • 2. Who?
    What?
    Why?
    When?
    How?
    4W1H
    Y & I
    Structure/Participants
    Consequences
    Applicability
    Implementation
  • 3. Intent
    “Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.”
  • 4. Real life analogy
    Copy Machine
  • 5. Real life analogy
    Copy Machine
    Product Prototypes
    Die Sinking
  • 6. structure
  • 7. structure
    Prototype
    Concrete
    Concrete
    Client
    Clone()
    Clone()
    Clone()
    Operation()
    p = prototype->Clone()
    Return copy of itself
    Return copy of itself
  • 8. participants
    Prototype
    Declares an instance for cloning itself
    Concrete Prototype
    Implement an operation of cloning itself
    Client
    Creates an object by asking the prototype to clone itself
  • 9. consequences
    Specifying new objects by varying values.
    Specifying new objects by varying structure.
    Reduced subclassing.
    Configuring an application with classes dynamically.
    Adding and removing products at run-time.
  • 10. applicability
    When a system should be independent of how its products are created, composed, and represented.
    When the classes to instantiate are specified at run-time
    To avoid building a class hierarchy of factories that parallels the class hierarchy of products
    When instances of a class can have one of only a few different combinations of state.
  • 11. Implementation issues
    Implementing the Clone operation.
    Binding the concrete prototypes
  • 12. Copy Constructor
    VS
    Prototype Pattern
  • 13. Shallow Copy
    VS
    Deep Copy
  • 14. Implementation issues
    Implementing the Clone operation.
    Binding the concrete prototypes
  • 15. structure
    ?
    Prototype
    Concrete
    Concrete
    Client
    Clone()
    Clone()
    Clone()
    Operation()
    p = prototype->Clone()
    Return copy of itself
    Return copy of itself
  • 16. Factories
    Factory:
    private ConcreteA* _prototypeA; // we can have more
    Factory:
    public MakeA() { return _prototypeA->clone(); }
    Client:
    Base* obj = MakeA();
    Client:
    obj->MoreActions();
  • 17. Prototype managers
    Create and destroy prototype at run-time
    Register new prototypes
    Unregister prototypes
    Client retrieve and store prototype from prototype manager
    Use map<key,prototype>
  • 18. CASE STUDY - tetris
  • 19. Tetris cont.
  • 20. Tetris cont.
  • 21. Tetris cont.
  • 22. Tetris cont.
  • 23. Tetris Cont.
  • 24. Tetris cont.
  • 25. Tetris cont.
  • 26. Tetris cont.
  • 27. One more thing
    Thank You!