Kyle Chen's Blog

Action speaks louder than Words

0%

外观模式C++实现

ref: 外观模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include<iostream>
using namespace std;
class Control{
public:
virtual ~Control() = default;
virtual void start()=0;
virtual void close()=0;
};
class Screen: public Control{
public:
void start(){
cout<<"the screen start!"<<endl;
}
void close(){
cout<<"the screen close!"<<endl;
}

};

class Keyboard: public Control{
public:
void start(){
cout<<"the Keyboard start!"<<endl;
}
void close(){
cout<<"the Keyboard close!"<<endl;
}
};

class Host: public Control{
public:
void start(){
cout<<"the Keyboard start!"<<endl;
}
void close(){
cout<<"the Keyboard close!"<<endl;
}
};

class Computer{
private:
Host host;
Keyboard keyboard;
Screen screen;
public:
void start(){
host.start();
keyboard.start();
screen.start();
}

void close(){
host.close();
keyboard.close();
screen.close();
}


};


int main(){

Computer computer;
computer.start();
computer.close();

}