-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.cpp
68 lines (58 loc) · 1.61 KB
/
main.cpp
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
/*
* @FileName : facade/main.cpp
* @CreateAt : 2022/4/16
* @Author : Inno Fang
* @Email : innofang@yeah.net
* @Description: Simple implementation of facade pattern
*/
#include <iostream>
class SubSystemA {
public:
void operationA() {
std::cout << "SubSystemA: operationA" << std::endl;
}
};
class SubSystemB {
public:
void operationB() {
std::cout << "SubSystemB: operationB" << std::endl;
}
};
class Facade {
public:
Facade(SubSystemA *subSystemA = nullptr, SubSystemB *subSystemB = nullptr) {
_sub_system_a = subSystemA ? subSystemA : new SubSystemA;
_sub_system_b = subSystemB ? subSystemB : new SubSystemB;
}
~Facade() {
delete _sub_system_a;
delete _sub_system_b;
}
void operationA() {
_sub_system_a->operationA();
}
void operationB() {
_sub_system_b->operationB();
}
void operationMix() {
std::cout << "Mix operationA and operationB:" << std::endl;
std::cout << "=> Ready perform operationA:" << std::endl;
_sub_system_a->operationA();
std::cout << "=> Ready perform operationB:" << std::endl;
_sub_system_b->operationB();
}
private:
SubSystemA *_sub_system_a;
SubSystemB *_sub_system_b;
};
int main() {
auto facade = new Facade;
std::cout << "\nPerform operationA separately" << std::endl;
facade->operationA();
std::cout << "\nPerform operationB separately" << std::endl;
facade->operationB();
std::cout << "\nPerform by mixing operation" << std::endl;
facade->operationMix();
delete facade;
return 0;
}