2019-11-10 02:50:30 +00:00
|
|
|
|
#ifndef __DEMO_H__
|
|
|
|
|
#define __DEMO_H__
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ࣨ<EFBFBD><E0A3A8><EFBFBD>ࣩ
|
|
|
|
|
class AbstractClass
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-04-04 13:09:08 +00:00
|
|
|
|
virtual ~AbstractClass(){}
|
2019-11-10 02:50:30 +00:00
|
|
|
|
// ģ<>巽<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
|