Template method Mode:
The skeleton of an algorithm is defined in a method, and some steps are deferred to subclasses. The template method allows subclasses to redefine some of the implementations in the algorithm without changing the structure of the algorithm.
Hollywood principles:
Don't call (call) us, we'll call (call) you.
Points:
1, "Template Method" defines the steps of the algorithm, the implementation of these steps to defer to the subclass
2. Template method mode provides us with an important technique for code reuse.
3. Abstract classes of template methods can define concrete methods, abstract methods, and hooks
4. The abstract method is implemented by subclasses
5, Hook is a method, it does not work in the abstract class, or only do the default things, subclasses can choose to do not overwrite it
6, in order to prevent subclasses from changing the algorithm in the template method, the template method can be declared as final
7. Hollywood principles tell us to put decision-making right in a high-level module in order to decide how to call the underlying module in time
8. You will see many variants of template method patterns in real-world code, and don't expect them to be recognized by you at a glance.
9, the Strategy mode and the template method pattern all encapsulate the algorithm, one uses the combination, one uses the inheritance
10, engineering method is a special version of the template method
Java design Pattern----Template Method pattern