// ProxyTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; //定义一个操作中的算法的骨架,而将一些步骤延迟到子类中。TemplateMethod 使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤 class AbstractClass { public: virtual ~AbstractClass(void) { } void TemplateMethod(void) { PrimitiveOperation0(); PrimitiveOperation1(); } virtual void PrimitiveOperation0(void) = 0; virtual void PrimitiveOperation1(void) = 0; }; class ConcreateClass : public AbstractClass { public: virtual void PrimitiveOperation0(void) { cout << "0" << endl; } virtual void PrimitiveOperation1(void) { cout << "1" << endl; } }; int _tmain(int argc, _TCHAR* argv[]) { AbstractClass* pAbstractClass = new ConcreateClass; pAbstractClass->TemplateMethod(); delete pAbstractClass; return 0; }