外观模式中提供一个统一的接口,然后对外观操作,内部成员可以不相同。
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