Template Method Pattern templates

Source: Internet
Author: User

Template Templates Method mode
function : Defines the skeleton of an algorithm in an operation. Some steps are deferred to subclasses, and the template method allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm.

The sub-algorithm in the algorithm template of the base class, which is set as a virtual function, is implemented in subclasses, and similar ideas can be referred to in another blog post.

http://www.cnblogs.com/xiumukediao/p/4637071.html multiple inheritance, there are different types of virtual functions in the base class, what to do? , it's kind of similar.

//TemplateMode.cpp:Defines the entry point for the console application.//#include"stdafx.h"#include<IOSTREAM>using namespacestd;classabstract{ Public:    Virtual voidtemplateoprate () { This-Operation1 ();  This-Operation2 (); }        Virtual voidOperation1 () =0; Virtual voidOperation2 () =0;};classConcreatechild1: Publicabstract{ Public:    voidOperation1 () {cout<<"Child1:operation1"<<Endl; }    voidOperation2 () {cout<<"Child1:operation2"<<Endl; }};classConcreatechild2: Publicabstract{ Public:    voidOperation1 () {cout<<"Child2:operation1"<<Endl; }    voidOperation2 () {cout<<"Child2:operation2"<<Endl; }};intMainintargcChar*argv[]) {Abstract* pchild =NewConcreatechild1; Pchild-templateoprate (); Pchild=NewConcreatechild2; Pchild-templateoprate (); return 0;}

Template Method Pattern templates

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.