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
相关推荐
oOOpHQYUKG12 天前
COMSOL激光淬火相变模拟
外观模式
白太岁12 天前
Redis:(3) Lua 与 Redis、基于连接池的 Facade 模式封装
数据库·c++·redis·lua·外观模式
SHeqSpMeS21 天前
PID 和 LQR 主动悬架模型对比:探索汽车平顺性的优化之路
外观模式
懵萌长颈鹿21 天前
外观模式 (Facade Pattern)
外观模式
wVAkMDmzEWcm1 个月前
易语言实现Jlink烧录程序:打造自动化烧录利器
外观模式
蔺太微1 个月前
外观模式(Facade Pattern)
设计模式·外观模式
小码过河.1 个月前
设计模式——外观模式
设计模式·外观模式
Engineer邓祥浩2 个月前
设计模式学习(12) 23-10 外观模式
学习·设计模式·外观模式
Geoking.2 个月前
【设计模式】外观模式(Facade)详解
java·设计模式·外观模式
sxlishaobin2 个月前
设计模式之外观模式
java·设计模式·外观模式