The template method mode seems easy to understand.
The main idea is to define an abstract class and put the method to be implemented in it, that is, the template. Then implement these methods in the specific subclass. The purpose is to increase the scalability of the class. Based on this template, different implementation methods may vary depending on the situation.
This mode is also easy to understand in practice, and the most typical is database connection and access.
To add applicationsProgramDevelopers will design their own programs to support as many database types as possible. However, different databases vary from connection methods to SQL queries. In this case, the template method is used.
Define an abstract data connection category class, list all attributes and methods as templates, and then write the corresponding implementation subclass for different databases. During the application, the corresponding subclass is called based on the database connection information configured by the system.
In object-oriented programs, inheritance is always essential, and the parent class is the template of the subclass. Therefore, this mode is everywhere.