本文共 902 字,大约阅读时间需要 3 分钟。
有时不想对内部了解太多,只想获得一个接口,facade模式最好不过。
1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 class Subsystem1 {12 public:13 void Operation() {14 cout << "operation 1\n";15 }16 17 };18 19 class Subsystem2 {20 public:21 void Operation() {22 cout << "operation 2\n";23 }24 25 };26 27 class Facade {28 public:29 Facade() {30 _subs1 = new Subsystem1();31 _subs2 = new Subsystem2();32 }33 ~Facade() {34 delete _subs1;35 delete _subs2;36 }37 void OperationWrapper() {38 _subs1->Operation();39 _subs2->Operation();40 }41 42 private:43 Subsystem1* _subs1;44 Subsystem2* _subs2;45 };46 47 int main() {48 Facade kaka;49 kaka.OperationWrapper();50 return 0;51 }
转载于:https://www.cnblogs.com/kakamilan/archive/2012/07/24/2606704.html