-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfacade.cpp
49 lines (43 loc) · 1.23 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
/*!
* \brief Facade. Provide a unified interface to a set of
* interfaces in a subsystem. Facade defines a higher-level
* interface that makes the subsystem easier to use.
*/
#include <iostream>
class LetterProcess {
public:
void WriteContext(const std::string &context) {
std::cout << "Context: " << context.c_str() << std::endl;
}
void FillEnvelope(const std::string &address) {
std::cout << "Address: " << address.c_str() << std::endl;
}
void PutIntoEnvelope() {
std::cout << "Put the letter into Envelope." << std::endl;
}
void SendLetter() {
std::cout << "Send Letter." << std::endl;
}
};
// Facade.
class PostOffice {
public:
// A higher-level interface.
void SendLetter(const std::string &context, const std::string &address) {
process_.WriteContext(context);
process_.FillEnvelope(address);
process_.PutIntoEnvelope();
process_.SendLetter();
}
private:
LetterProcess process_;
};
int main() {
PostOffice *post_office = new PostOffice();
const std::string context = "Hello";
const std::string address = "Beijing";
// Use an interface to complete the entire process of sending letter.
post_office->SendLetter(context, address);
delete post_office;
return 0;
}