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
相关推荐
思忖小下5 天前
c#代码介绍23种设计模式_11外观模式
设计模式·c#·外观模式
多喝热水-多读书8 天前
Qt C++设计模式->外观模式
c++·qt·设计模式·外观模式
林小果111 天前
外观模式
java·开发语言·设计模式·外观模式
java_heartLake12 天前
设计模式之外观模式
java·设计模式·外观模式
Liu_Junwei12 天前
设计模式--外观模式
设计模式·外观模式
仙魁XAN13 天前
Unity 设计模式 之 结构型模式 -【装饰者模式】【外观模式】【享元模式】【代理模式】
unity·设计模式·代理模式·享元模式·外观模式·装饰者模式
coffee_baby22 天前
外观模式详解:如何为复杂系统构建简洁的接口
java·spring boot·spring cloud·java-ee·maven·mybatis·外观模式
会敲代码的小张22 天前
设计模式-外观模式
java·开发语言·后端·设计模式·外观模式
磊-22 天前
九、外观模式
外观模式
AI让世界更懂你22 天前
漫谈设计模式 [9]:外观模式
python·设计模式·外观模式