代码没有按照规范写~~
class Library{
protected:
virtual ~Library(){}
bool step1(){ //稳定
//...
}
bool step2(){//稳定
//...
}
virtual bool step3() = 0;//变化
bool step4(){//稳定
//...
}
virtual bool step5() = 0;//变化
//“稳定”中有“变化 ” step1 step2 step 4是稳定的,step3、step5是变化的
//这个程序框架 也就是 run是“稳定”的
void run(){
step1();
if(step2()){
step3(); //支持变化 虚函数的多态调用
}
for(int i=0;i<4;i++){
step4();
}
step5();//支持变化 虚函数的多态调用
}
};
class UserApp : public Library{
bool step3(){
//具体实现
}
bool step5(){
//具体实现
}
};
int main(){
Library* task = new UserApp();
task->run();
delete task;
}