Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Prototype Design Pattern

2,346 views

Published on

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

  • Login to see the comments

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>

×