Prototype Design Pattern

1,713 views

Published on

Talk given at the Melbourne Patterns Group Meeting in March 2009.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,713
On SlideShare
0
From Embeds
0
Number of Embeds
56
Actions
Shares
0
Downloads
50
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Prototype Design Pattern

  1. 1. From Design Patterns (Gamma et al)‏ Presented by David Kemp Melbourne Patterns Group
  2. 2. Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype. Design Patterns, Gamma et al, Chapter 4.
  3. 4. Creational Patterns <ul><li>Abstract Factory </li></ul><ul><li>Builder </li></ul><ul><li>Factory Method </li></ul><ul><li>Prototype </li></ul><ul><li>Singleton </li></ul>
  4. 6. Image from Flickr by Bob Henry Photography (http://flickr.com/photos/bobasonic/170043435/)‏ Some rights reserved (http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en)‏
  5. 7. <ul><li>Alternative to Factory Method and Abstract Factory. </li></ul><ul><li>Can be used to implement Abstract Factory. </li></ul><ul><li>To avoid building a class hierarchy of factories. </li></ul><ul><li>Can be used when loading classes dynamically </li></ul><ul><li>Often can use class objects instead. </li></ul>
  6. 8. Image from Flickr by Slowburn / Andreas Schaefer ( http://flickr.com/photos/slowburn/70150248/ )‏ Some rights reserved (http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en)‏
  7. 9. <ul><li>Add/Remove prototypes at runtime. </li></ul><ul><li>Specify new prototypes by varying data. </li></ul><ul><li>Specify new prototypes by varying structure. </li></ul><ul><li>Less classes (less sub-classing!)‏ </li></ul><ul><li>Dynamic class loading. </li></ul>
  8. 10. Discussion <ul><li>Factory Method: delegate to subclasses. </li></ul><ul><li>AbstractFactory, Builder, and Prototype: delegate to another class. </li></ul><ul><li>Prototype: reduces the total number of classes. </li></ul><ul><li>Builder: Good when construction logic is complex. </li></ul>

×