DesignPattern/23.TemplateMethodPattern/2.Code/Demo.h

41 lines
594 B
C
Raw Normal View History

2019-11-10 02:50:30 +00:00
#ifndef __DEMO_H__
#define __DEMO_H__
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0A3A8><EFBFBD>
class AbstractClass
{
public:
// ģ<><EFBFBD><E5B7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void templateMethod(){
// do something
method1();
method2();
method3();
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void mehtod1(){
// do something
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
virtual void method2() = 0;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>ʵ<EFBFBD><CAB5>
void mehtod3(){
// do something
}
};
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E0A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
class ConcreteClass :public AbstractClass
{
public:
// ʵ<>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
void method2(){
// do something
}
// <20>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD>ǻ<EFBFBD><C7BB><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>3
void method3(){
// do something
}
};
#endif