N/APosted on - 12/06/2011
According to the Gang of Four, the commitment of the template procedure pattern is to "determine the skeleton of an algorithm in an operation, suspend some procedure of subclasses. Identify the steps of algorithm without changing the algorithm's structure". What does this mean?
Determining the usage of Algorithms
Template procedure pattern requires implementation of an abstract base class and derived class(es). Derived classes are also referred as component's clients or subclasses.
Abstract base class provides the general implementation of algorithm. This general implementation has some invariant and variant components. Invariant components are those steps of algorithm that can not be changed or dictated by the derived classes. Abstract base class provide complete implementation for invariant components. Variant components, which are represented as abstract placeholders, can or must be implemented by the derived classes.
It should be noted here that the number and order of algorithmic steps to be performed is defined with definition of abstract base class. However, derived classes are allowed to extend or replace the variant components.
The best implementation example of template procedure pattern is that of frameworks. Frameworks provide implementation of invariant components, and abstract placeholders for interesting or required client customization options. This makes the frameworks the center of universe, and leaves the room for extension and/or enhancements to the client component(s).