The template method
The template method pattern is a simple pattern used when you need a general behavior but where the details of the algorithm must be specific to subclasses.
Role
The template method pattern isolates various parts of an algorithm. The algorithm skeleton is defined in an abstract class where some steps of the algorithm are delegated to its subclasses and some others are fixed in the abstract class itself and cannot be overridden in subclasses.
Design
The following diagram describes the generic structure of the template method:

Participants
The participants of this pattern are as follows:
The
AbstractClass
, which defines the template method, and the signature of the sub parts of the algorithm are invoked by the template method.The
ConcreteClass
implements abstract methods used by the template method of theAbstractClass
. It is possible to have several concrete classes.
Collaboration
The algorithm defined in the template method is called TemplateMethod()
in the generic UML class diagram...