-
Notifications
You must be signed in to change notification settings - Fork 0
/
FacadeDesignPattern.cpp
102 lines (93 loc) · 2.05 KB
/
FacadeDesignPattern.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
using namespace std;
// Subsystem Components
class DVDPlayer {
public:
void on() {
cout << "DVD Player is ON" << endl;
}
void play(const string& movie) {
cout << "Playing: " << movie << endl;
}
void off() {
cout << "DVD Player is OFF" << endl;
}
};
class Projector {
public:
void on() {
cout << "Projector is ON" << endl;
}
void setInput(const string& input) {
cout << "Setting input to: " << input << endl;
}
void off() {
cout << "Projector is OFF" << endl;
}
};
class Amplifier {
public:
void on() {
cout << "Amplifier is ON" << endl;
}
void setVolume(int volume) {
cout << "Setting volume to: " << volume << endl;
}
void off() {
cout << "Amplifier is OFF" << endl;
}
};
class Screen {
public:
void up() {
cout << "Screen is UP" << endl;
}
void down() {
cout << "Screen is DOWN" << endl;
}
};
// Facade
class HomeTheaterFacade {
private:
DVDPlayer dvdPlayer;
Projector projector;
Amplifier amplifier;
Screen screen;
public:
void watchMovie(const string& movie) {
cout << "Get ready to watch a movie..." << endl;
dvdPlayer.on();
dvdPlayer.play(movie);
projector.on();
projector.setInput("DVD Player");
amplifier.on();
amplifier.setVolume(10);
screen.down();
}
void endMovie() {
cout << "Shutting down the home theater..." << endl;
dvdPlayer.off();
projector.off();
amplifier.off();
screen.up();
}
};
int main() {
// Using the Facade to simplify interactions
HomeTheaterFacade homeTheater;
// Watch a movie
string movie;
cin>>movie;
homeTheater.watchMovie(movie);
cout<<endl;
while(true){
//Command to end the movie
cout<<"Press 'q' to end movie..."<<endl;
string s; cin>>s;
if(s=="q"){
homeTheater.endMovie();
break;
}
}
return 0;
}