The
template method pattern defines the skeleton of an algorithm in one method, and some steps are deferred to subclasses. The template method allows subclasses to redefine some of the steps in the algorithm without changing the structure of the algorithm. A template is a method. This method defines the algorithm as a set of steps, in which any step can be abstract and the subclass is responsible for implementing it. This ensures that the algorithm structure remains the same, while the subclass provides partial implementations.
Note: 1, in order to prevent the subclass change the template method in the algorithm, the template method can be declared final, 2, the policy mode and template method pattern are encapsulated algorithm, a use of combination, one with inheritance; 3, the factory method is a special version of the template method;
Template method Pattern of design pattern learning notes