Prototype mode structure
Advantage 1, one of the main advantages of Prototype mode, dynamically increase / set Classs.
In the case of the book, you can arbitrarily create subclasses of Graphic, while Graphictool does not need to know the name of the specific Graphic subclass, just pass him a prototype (a pointer to the new class), you can Generate new objects by calling Clone.
2, the main advantage of Prototype mode can reduce many schools.
Considering a problem in AbstractFactory, when you use the FactoryMethod mode to generate products, you need to derive a corresponding ConcreteFactory class for every Family. In this way, the number of ConcreteFactory classes is in parallel with Product's Family. To use prototype, just a ConcreteFactory, you can create any Family's Product.
Note: Since this figure is made of standard UML, it is somewhat different from the book. However, it means that other chairs in the book are consistent. That is, a solid line with an arrow indicates a reference, the dotted line is created.
Disadvantages of each prototype need to implement Clone operations.
Explore the contrast of Template in C ?
Reference: "Design Pattern" Gang-Of-4 1997
Jady Leung
October 5, 2004