外观模式(二)

#include <iostream>

using namespace std;

class Memory{
public:
    void check(){
        cout<<"内存自检"<<endl;
    }
    void off(){
        cout<<"内存关闭"<<endl;
    }
};

class Cpu{
public:
    void run(){
        cout<<"CPU运行"<<endl;
    }
    void off(){
        cout<<"CPU关闭"<<endl;
    }
};

class HardDisk{
public:
    void read(){
        cout<<"硬盘读取"<<endl;
    }
    void off(){
        cout<<"硬盘关闭"<<endl;
    }
};

class Os{
public:
    void load(){
        cout<<"操作系统加载"<<endl;
    }
    void off(){
        cout<<"操作系统关闭"<<endl;
    }
};

class MainFrame{
private:
    Memory w1;
    Cpu w2;
    HardDisk w3;
    Os w4;
public:
    void on(){
        cout<<"开机中......"<<endl;
        w1.check();
        w2.run();
        w3.read();
        w4.load();
    }
    void off(){
        cout<<"关机中......"<<endl;
        w1.off();
        w2.off();
        w3.off();
        w4.off();
    }
};


int main(){
    MainFrame w;
    w.on();
    w.off();
    return 0;
}

 

posted @ 2022-11-03 20:21  今天又双叒叕在敲代码  阅读(23)  评论(0编辑  收藏  举报