码迷,mamicode.com
首页 > 其他好文 > 详细

设计模式15——外观模式

时间:2015-06-19 21:27:16      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

外观模式中提供一个统一的接口,然后对外观操作,内部成员可以不相同。

 1 #ifndef Facade_H_H
 2 #define Facade_H_H
 3 
 4 class A{
 5 public:
 6     void showA(){
 7         cout << "This is class A" << endl;
 8     }
 9 };
10 
11 class B{
12 public:
13     void showB(){
14         cout << "This is class B" << endl;
15     }
16 };
17 
18 class C{
19 public:
20     void showC(){
21         cout << "This is class C" << endl;
22     }
23 };
24 
25 class Facade{
26 public:
27     Facade(){
28         pA = new A();
29         pB = new B();
30         pC = new C();
31     }
32 
33     void show(){
34         pA->showA();
35         pB->showB();
36         pC->showC();
37     }
38 
39     ~Facade(){
40         delete pA;
41         delete pB;
42         delete pC;
43     }
44 
45 private:
46     A *pA;
47     B *pB;
48     C *pC;
49 };
50 
51 
52 void FacadeTest(){
53     Facade *facade = new Facade();
54     facade->show();
55 
56     delete facade;
57 }
58 
59 #endif

 

设计模式15——外观模式

标签:

原文地址:http://www.cnblogs.com/MiniHouse/p/4589628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!