Design Patterns: Prototype

Posted by Monik, 12 October 2010.
Programming Code Design Design Patterns
Book summary
Summary on basis of the book ,,Design Patterns: Elements of Reusable Object-Oriented Software'', by Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides, Addison-Wesley, 1995.


class GraphicTool{
draw(){
...
Product p = this.prototype.clone();
p.draw();
...
}
}
We use it when we do not know the class' type (Product) to instatiate at compiliation time. In this way we avoid building a factory for each Product type. We can also use this pattern if we are going to use many instances of Product with similar state (as this way it is more convenient).

Consequences:
Variations:

Comments


Comments: