Template method
1. Intent to define the skeleton of an algorithm in an operation, delay some steps into subclasses, and Template method allows subclasses to redefine some steps of the algorithm without altering the structure of an algorithm. 2. Motivation takes into account an application framework that provides application and document classes. The application class is responsible for opening a document that already has an external storage form, such as a file. Once a file's information is read from the file, it is represented by a Document object. We call the OpenDocument method a template method, a template method that defines an algorithm with an abstract operation, and subclasses redefine these operations to provide specific behavior. The subclasses of application will define specific algorithmic steps to check whether a document can be opened (canopendocument) and create a document (Docreatedocument). The document subclass mydocument defines the algorithm steps (Doread) for reading the documents. By using abstract operations to define one or more of the steps in the algorithm, the template method determines their sequencing, but it allows the application and document subclasses to change these steps to meet their needs. 3. Applicability one-time implementation of the invariant part of the algorithm, the variable part to the subclass implementation of the common behavior of each subclass should be extracted and centralized into the parent class to avoid the extension of the code repeating subclass by the parent class control 4. Structure 5. Collaboration Concreteclass by AbstractClass to achieve the same algorithm in step 6. The effect template method is a basic technique of code reuse, which is especially important in the class library, which provides the public behavior of the class library. The template method leads to a reverse control structure, the "Hollywood Rule", "Don't look for us, we're looking for you", referring to the action of the parent class calling the subclass, not the other way around. 7. Practice very common design patterns, through the parent class definition framework, subclasses to populate
Template method of design pattern