//应用程序开发人员classApplication{public:boolStep2(){//...}voidStep4(){//...}};intmain(){Library lib();Application app();lib.Step1();if(app.Step2()){lib.Step3();}for(int i =0; i <4; i++){app.Step4();}lib.Step5();}
2.代码二 – 面向对象
1.lib.cpp
//程序库开发人员classLibrary{public://稳定 template methodvoidRun(){Step1();if(Step2())//支持变化 ==> 虚函数的多态调用{Step3();}for(int i =0; i <4; i++){Step4();//支持变化 ==> 虚函数的多态调用}Step5();}virtual~Library(){}protected:voidStep1()//稳定{//.....}voidStep3()//稳定{//.....}voidStep5()//稳定{//.....}virtualboolStep2()=0;//变化virtualvoidStep4()=0;//变化};