"Design Mode Design Pattern" reading notes twenty
Template Method mode
structure
purpose
In the parent class define a framework of an algorithm, it can make each step in the change in the subclass in the subclass. Thus, the subclass can invitrate a specific step in the algorithm, but the structure of the entire algorithm has not changed.
discuss
1. PrimitiveOperation can be a pure virtual function; or just a virtual function, the parent class provides a default implementation.
2, PrimitiveOperation can be a function of protected type, which ensures that they are only called by TemplateMethod.
Differences with other modes
Template Methods achieves different implementations of the algorithms through inheritance; Strategies produces a complete different algorithm by delegation.
Reference
"Design Pattern" Gang-Of-4 1997