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
相关推荐
工一木子3 天前
【HeadFirst系列之HeadFirst设计模式】第8天之适配器模式与外观模式:让不兼容的接口和谐共处!
设计模式·适配器模式·外观模式
扣丁梦想家3 天前
设计模式教程:外观模式(Facade Pattern)
设计模式·外观模式
強云3 天前
23种设计模式 - 外观模式
设计模式·外观模式
hope_wisdom5 天前
实战设计模式之外观模式
设计模式·架构·软件工程·软件构建·外观模式·架构设计
熊出没5 天前
解锁外观模式:Java 编程中的优雅架构之道
java·架构·外观模式
好好学习++7 天前
【HF设计模式】07-适配器模式 & 外观模式
java·c++·设计模式·适配器模式·外观模式
找了一圈尾巴7 天前
设计模式-代理模式、外观模式
设计模式·代理模式·外观模式
鎈卟誃筅甡10 天前
JavaScript设计模式 -- 外观模式
外观模式
游客52011 天前
设计模式-结构型-外观模式
开发语言·python·设计模式·外观模式
管大虾11 天前
设计模式-外观模式
设计模式·外观模式