11.外观模式

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

UML

测试代码

cpp 复制代码
#include <iostream>
using namespace std;
 
class SubSystemOne
{
public:
    void MethodOne(){
        cout << "MethodOne" << endl;
    }
};
class SubSystemTwo
{
public:
    void MethodTwo(){
        cout << "MethodTwo" << endl;
    }
};
 
class SubSystemThree
{
public:
    void MethodThree(){
        cout << "MethodThree" << endl;
    }
};
 
class SubSystemFour
{
public:
    void MethodFour(){
        cout << "SubSystemFour" << endl;
    }
};
 
class Facade
{
    SubSystemOne one;
    SubSystemTwo two;
    SubSystemThree three;
    SubSystemFour four;
public:
    void MethodA(){
        cout << endl << "方法组A()" << endl;
        one.MethodOne();
        two.MethodTwo();
        four.MethodFour();
    }
    void MethodB(){
        cout << endl << "方法组B()" << endl;
        one.MethodOne();
        three.MethodThree();
        four.MethodFour();
    }
};
 
int main(void)
{
    Facade f;
    f.MethodA();
    f.MethodB();
    return 0;
}

运行结果

复制代码
方法组A()
MethodOne
MethodTwo
SubSystemFour
 
方法组B()
MethodOne
MethodThree
SubSystemFour
相关推荐
likerhood4 天前
设计模式 · 外观模式(Facade Pattern)
设计模式·外观模式
c++之路4 天前
外观模式(Facade Pattern)
算法·外观模式
蜡笔小马7 天前
09.C++设计模式-外观模式
c++·设计模式·外观模式
多加点辣也没关系11 天前
设计模式-外观模式
设计模式·外观模式
雪度娃娃11 天前
结构型设计模式——外观模式
c++·设计模式·外观模式
geovindu1 个月前
go: Facade Pattern
设计模式·golang·外观模式
ximu_polaris1 个月前
设计模式(C++)-结构型模式-外观模式
c++·设计模式·外观模式
我爱cope1 个月前
【从0开始学设计模式-11| 外观模式】
microsoft·设计模式·外观模式
Rsun045511 个月前
9、Java 外观模式从入门到实战
java·开发语言·外观模式
大数据新鸟2 个月前
设计模式详解——外观模式
设计模式·外观模式