Introduction of Template Method pattern (Brief Introduction)
Template method Patterns (Template methods pattern) that define an algorithm skeleton in an operation and delay some steps into subclasses. Template methods allow subclasses to redefine some specific steps of an algorithm without altering the structure of an algorithm. The template method pattern moves the invariant behavior to the superclass, eliminating the duplicated code in the subclass, and in fact the template method pattern provides a code reuse platform.
Ii. issues addressed (What to Solve)
To complete a process or a series of steps that are level-consistent in a particular detail, the individual steps are not implemented at a more detailed level, and you can use the template method pattern to solve the problem.
Three, template method pattern Analysis 1, template method pattern structure
Abstract class AbstractClass, implements a template method, defines an algorithm framework, the specific subclass will redefine PrimitiveOperation1 and PrimitiveOperation1 to implement an algorithm step.
Subclasses Concreteclassa and CONCRETECLASSB to implement PrimitiveOperation1 and PrimitiveOperation1 to complete the steps associated with a particular subclass in the algorithm.