Template method Mode
English name
Template Method Pattern
definition
The skeleton of an algorithm is defined in a method, and some steps are deferred to subclasses, and the template method allows subclasses to redefine some of the steps in the algorithm without altering the algorithm structure.
Principles
Hollywood principles: Don't call us, we'll call you.
Talk to friends only
Understanding
1. There is an abstract class, which has a concrete method, which is an algorithm that calls a series of algorithmic methods. Some of these methods are abstract methods, leaving the subclasses to implement their own special. Some methods are implemented specifically, and the descriptions are attributes common to subclasses.
2. Hook implementation, the hook will determine whether to invoke a method in the algorithm, the parent class can have a default implementation, subclasses can also implement their own. This makes it possible for subclasses to change the algorithm of the parent class.