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
相关推荐
Java后端的Ai之路2 天前
21、Python - 命令模式
开发语言·人工智能·python·命令模式·外观模式
码匠许师傅3 天前
【设计模式精讲】14.外观模式(Facade)
c++·设计模式·uml·外观模式
Java后端的Ai之路4 天前
17、Python - 观察者模式
开发语言·人工智能·python·观察者模式·外观模式
geovindu1 个月前
java: Facade Pattern
java·开发语言·后端·外观模式·结构型模式
wWYy.2 个月前
外观模式(Facade Pattern)
sdk·外观模式
我登哥MVP2 个月前
走进 Gang of Four 设计模式:外观模式
java·设计模式·外观模式
ttod_qzstudio2 个月前
【软考设计模式】外观模式:复杂子系统的“门面“封装与代码填空精讲
设计模式·外观模式
老码观察3 个月前
设计模式实战解读(十一):外观模式——给复杂系统套一层壳
python·设计模式·外观模式
咖啡八杯3 个月前
GoF设计模式——外观模式
java·设计模式·外观模式
likerhood4 个月前
设计模式 · 外观模式(Facade Pattern)
设计模式·外观模式