Design Patterns-Template methods

Source: Internet
Author: User

Template

Https://www.collinsdictionary.com/dictionary/english/template

1. Countable noun

A template is a thin piece of metal or plastic which are cut into a particular shape. It's used to help you cut wood, paper, metal, or other materials accurately, or to reproduce the same shape many times.

Trace around your template and transfer the design onto a sheet of card.

2. countable noun [usually singular]

If One thing is a template for something else, the second thing are based on the first thing.

The deal is likely-provide a template for other agreements. [+ for]

As can be seen from the above definition, the template is not directly available, but is used to produce the tools available, the production of things and templates have the same shape.

There are many scenes in life that use the idea of a template:

For example: poster template, download a beautifully styled poster template, the personalized content of which to be promoted information, then a beautiful poster quickly produced.


For the above example: poster template, the entire mold is unchanged, for any of the generated posters, the overall style is consistent;

This template is open for users to modify the section, generally using XXX annotations, which belong to the template placeholder, need to replace the user with their own information.


Poster Template---Abstract

The user-made poster---is specific and inherits the overall styling style of the poster template.


Template method

2911246


The template method Gof is defined by defining the skeleton of the algorithm in a method, deferring some steps to its subclasses. Such as:


AbstractClass is primarily a skeleton of an algorithm that defines an operation, and some steps are deferred to subclasses. Templatemethod allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm. This is a bit like a "hook" in C, while porting the common code to Templatemethod, which implements the common code.



Understanding: The template method is an abstract method, this method does not work directly, because in fact, there are several methods in this method that are not implemented,

This method, which needs to be implemented in a subclass.


Thus by the following relationship:

Abstract class------Define template methods && define virtual methods (abstract functions called in template methods)

The skeleton of the program algorithm is constructed as a template method, which belongs to the high level abstract logic.

Concrete classes------virtual methods that implement abstract class definitions, and each specific subclass has a different virtual method implementation.


Design Patterns-Template methods

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.