设计模式---外观模式

xiaoxiao2021-02-28  123

外观模式 为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。

#include<iostream>

using namespace std; class SubSystemOne {     public:         void MethodOne()         {             cout<<"system method 1 "<<endl;         } }; class SubSystemTwo {     public:         void MethodTwo()         {             cout<<"system method 2 "<<endl;         } }; class SubSystemThree {     public:         void MethodThree()         {             cout<<"system method 3 "<<endl;         } }; class SubSystemFour {     public:         void MethodFour()         {             cout<<"system method 4 "<<endl;         } }; class Facade {     SubSystemOne *one;     SubSystemTwo *two;     SubSystemThree *three;     SubSystemFour *four;     public:         Facade()         {             one = new SubSystemOne();             two = new SubSystemTwo();             three = new SubSystemThree();             four = new SubSystemFour();         }         void MethodA()         {             cout<<"method a..."<<endl;             one->MethodOne();             two->MethodTwo();         }         void MethodB()         {             cout<<"method b..."<<endl;             three->MethodThree();             four->MethodFour();         } }; int main() {     Facade *facade = new Facade();     facade->MethodA();     facade->MethodB();     return  0; }
转载请注明原文地址: https://www.6miu.com/read-33934.html

最新回复(0)