The structural mode is over, and the behavioral mode is started.
The first is the simplest, easiest, and most commonly used template method mode.
How do we define the template method mode? Simply put, it is to first define a skeleton (Framework Developer), and then implement the specific application (ApplicationProgramDeveloper) the specific content of such a skeleton, which is the template method ).
There are also many examples in life. We went to college to learn a professional course, such as car design. The knowledge that our textbooks and teachers teach us is template, basic knowledge, and framework knowledge. When we were hired by Toyota Motor, Honda Motor, and Dongfeng Motor after graduation, we designed a specific vehicle, which is the specific application implementation. Because the basic knowledge of automobile design is that security, torque, fuel saving, environmental protection standards, and so on must be considered. However, the specific business needs of a specific company depend on the specific business needs of the company.
The example may not be very appropriate. I hope I can give you some inspiration and ideas. If you have a better example, I hope you will not give it to me.
In specific implementation, tips: Write the virtual methods that constitute the template method mode as protected, and write the methods that use these virtual methods as public. In the mainstream development frameworks, this mode is almost everywhere. Such a simple reuse structure isCodeThere are changing requirements in the Process of reuse. In this case, it is most appropriate to use the template method mode. It is simple, easy to use, and widely used. It is a perfect solution for home travel and programming. It is a very basic design model, simple but important. In my opinion, it is a basic application of polymorphism technology. Don't call me, let me call you. A reverse structure is a typical application of the template method.
In a word, the template method mode is to use inheritance and polymorphism for simple code reuse and the structure to respond to specific application changes.
Thank you.