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