Template Method 模板方法模式代码

来源:互联网 发布:电脑软件管理 编辑:程序博客网 时间:2024/06/05 15:05
#include <iostream>#include <string>#include <vector>using namespace std;class ChannelController{    public:void turnOnAllChannels(){    bool StateOn = true;setChannel1(StateOn);setChannel2(StateOn);}protected:virtual void setChannel1(bool SwitchState)=0;virtual void setChannel2(bool SwitchState)=0;};class ChannelImplete:public ChannelController{    private:void setChannel1(bool SwitchState){            cout<<"setChannel1"<<endl;}void setChannel2(bool SwitchState){cout<<"setChannel2"<<endl;}};void main(){    ChannelImplete ChannleController;    ChannleController.turnOnAllChannels();   while(1);}

原创粉丝点击