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
相关推荐
大数据新鸟10 天前
设计模式详解——外观模式
设计模式·外观模式
无籽西瓜a10 天前
【西瓜带你学设计模式 | 第十期 - 外观模式】外观模式 —— 子系统封装实现、优缺点与适用场景
java·后端·设计模式·软件工程·外观模式
砍光二叉树16 天前
【设计模式】结构型-外观模式
设计模式·外观模式
青春易逝丶1 个月前
外观模式
外观模式
sg_knight1 个月前
外观模式(Facade)
开发语言·python·外观模式·facade
JTCC1 个月前
Java 设计模式西游篇 - 第九回:外观模式简化繁 如来神掌一指定
java·设计模式·外观模式
oOOpHQYUKG2 个月前
COMSOL激光淬火相变模拟
外观模式
白太岁2 个月前
Redis:(3) Lua 与 Redis、基于连接池的 Facade 模式封装
数据库·c++·redis·lua·外观模式
SHeqSpMeS2 个月前
PID 和 LQR 主动悬架模型对比:探索汽车平顺性的优化之路
外观模式
懵萌长颈鹿2 个月前
外观模式 (Facade Pattern)
外观模式