Vernacular design mode-behavior mode-template method mode (template method mode)

Source: Internet
Author: User

 

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.