Template method pattern of design pattern

Source: Internet
Author: User

The template method pattern is a very simple pattern because it uses only the inheritance relationship.

Template Method Mode: Defines the skeleton of an algorithm in an operation, and extends some of the steps into subclasses. Enables subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.

Let's look at the structure of this simple pattern:
1) Abstract class: Defines one or more abstract methods for specific subclasses to implement them, and implements a template method to define the skeleton of an algorithm. The template method not only invokes the previous abstract method, but also invokes other operations, as long as it can accomplish its own mission.
2) Concrete Class (concrete Class): Implements the abstract method in the parent class to complete the steps associated with a particular subclass in the algorithm.
The following is a schematic diagram of the template method pattern. Just take the diagram from the design pattern and use it:

Because the template method pattern is a very simple method, here is not an example.

Template method pattern of design pattern

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.