设计模式——外观模式(C++实现)

软件设计 2017-05-12

设计模式——外观模式(C++实现)

设计模式——外观模式(C++实现)

1 #include <string>
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 class STSystemA
 7 {
 8 public:
 9         void OperationA()
10         {
11                 cout<< "System A Operation....."<< endl;
12         }
13 };
14 
15 class STSystemB
16 {
17 public:
18         void OperationB()
19         {
20                 cout<< "System B Operation....."<< endl;
21         }
22 };
23 
24 class STSystemC
25 {
26 public:
27         void OperationC()
28         {
29                 cout<< "System C Operation....."<< endl;
30         }
31 };
32 
33 class STFacade
34 {
35 public:
36         STFacade()
37         {
38                 m_stSystemA = new STSystemA();
39                 m_stSystemB = new STSystemB();
40                 m_stSystemC = new STSystemC();
41         }
42 
43         virtual ~STFacade()
44         {
45                 delete m_stSystemA;
46                 delete m_stSystemB;
47                 delete m_stSystemC;
48         }
49 
50         void Operation()
51         {
52                 m_stSystemA->OperationA();
53                 m_stSystemB->OperationB();
54                 m_stSystemC->OperationC();
55         }
56 
57         STSystemA* m_stSystemA;
58         STSystemB* m_stSystemB;
59         STSystemC* m_stSystemC;
60 
61 };
62 
63 
64 int main(int argc, char* argv[])
65 {
66         STFacade* stFacade = new STFacade();
67         stFacade->Operation();
68 
69         delete stFacade;
70 
71         return 0;
72 }
73 /////////////////////////////////////
74 [root@ ~/learn_code/design_pattern/11_facade]$ ./facade       
75 System A Operation.....
76 System B Operation.....
77 System C Operation.....

相关推荐