Learn a little bit every day design pattern-Template Method mode

Source: Internet
Author: User
Tags abstract
Template method Mode


English name


Template Method Pattern


definition


The skeleton of an algorithm is defined in a method, and some steps are deferred to subclasses, and the template method allows subclasses to redefine some of the steps in the algorithm without altering the algorithm structure.


Principles


Hollywood principles: Don't call us, we'll call you.

Talk to friends only


Understanding


1. There is an abstract class, which has a concrete method, which is an algorithm that calls a series of algorithmic methods. Some of these methods are abstract methods, leaving the subclasses to implement their own special. Some methods are implemented specifically, and the descriptions are attributes common to subclasses.

2. Hook implementation, the hook will determine whether to invoke a method in the algorithm, the parent class can have a default implementation, subclasses can also implement their own. This makes it possible for subclasses to change the algorithm of the parent class.



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.