-
Notifications
You must be signed in to change notification settings - Fork 0
/
Facade.cpp
58 lines (45 loc) · 1.2 KB
/
Facade.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
/*
* Facade pattern
*
* Intent: provides simplified interface to complex system
*/
#include <iostream>
#include <memory>
class Subsystem1 {
public:
void subsystem1_get_ready() const {
std::cout << "Subsystem1: Ready!" << '\n';
}
void subsystem1_run() const {
std::cout << "Subsystem1 is currently running..." << '\n';
}
};
class Subsystem2 {
public:
void subsystem2_get_ready() const {
std::cout << "Subsystem2: Ready!" << '\n';
}
void subsystem2_run() const {
std::cout << "Subsystem2 is currently running..." << '\n';
}
};
class Facade {
public:
Facade() : _subsystem_1(), _subsystem_2() {}
// Facade does all setup of the system. Client only needs to call one method of facade to setup system.
void setup_system() {
_subsystem_1->subsystem1_get_ready();
_subsystem_2->subsystem2_get_ready();
_subsystem_1->subsystem1_run();
_subsystem_2->subsystem2_run();
}
protected:
std::unique_ptr<Subsystem1> _subsystem_1;
std::unique_ptr<Subsystem2> _subsystem_2;
};
int main() {
Facade facade;
// Client works with system through one convenient method
facade.setup_system();
return 0;
}