Interpreting Design Patterns----Template Method Patterns (Template methods)

Source: Internet
Author: User

I. Overview of the pattern

The touch-board approach (Template method) pattern is a very simple and often used design pattern. Create a parent class and leave one or more of these methods to the subclass to implement, which is actually using the touch-board mode. The so-called touch plate model can be interpreted as follows: "Define an algorithm in a class, However, some details of this algorithm are left to the subclass to implement. In other words, the base class is an abstract class, so you're using a simple form of touch-board mode.

One step closer to understanding this: "Prepares an abstract class, implements part of the logic as a concrete method, and then declares some abstract methods to force the subclass to implement the remaining logic. Different subclasses can implement these abstract methods in different ways, thus having different implementations of the remaining logic."

Two. Pattern Intent

Extracts the base part of a class into a base class so that it does not have to recur in several derived classes.

Three. Pattern UML diagram (The following image is transferred from http://www.dofactory.com/)

Four. Pattern structure and participant

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.