The template method pattern is a very simple pattern because it uses only the inheritance relationship.
Template Method Mode: Defines the skeleton of an algorithm in an operation, and extends some of the steps into subclasses. Enables subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.
Let's look at the structure of this simple pattern:
1) Abstract class: Defines one or more abstract methods for specific subclasses to implement them, and implements a template method to define the skeleton of an algorithm. The template method not only invokes the previous abstract method, but also invokes other operations, as long as it can accomplish its own mission.
2) Concrete Class (concrete Class): Implements the abstract method in the parent class to complete the steps associated with a particular subclass in the algorithm.
The following is a schematic diagram of the template method pattern. Just take the diagram from the design pattern and use it:
Because the template method pattern is a very simple method, here is not an example.
Template method pattern of design pattern