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 天前
设计模式学习(五)装饰者模式、桥接模式、外观模式
java·学习·设计模式·桥接模式·装饰器模式·外观模式
青草地溪水旁5 天前
第十章:外观模式 - 复杂系统的简化大师
外观模式
charlie1145141915 天前
精读C++20设计模式——结构型设计模式:外观模式
c++·学习·设计模式·c++20·外观模式
大飞pkz15 天前
【设计模式】外观模式
开发语言·设计模式·c#·外观模式
努力也学不会java1 个月前
【设计模式】 外观模式
设计模式·外观模式
找不到、了1 个月前
Java设计模式之《外观模式》
java·设计模式·外观模式
pengzhuofan2 个月前
Java设计模式-外观模式
java·设计模式·外观模式
LoveC5212 个月前
设计模式之外观模式
设计模式·外观模式
困鲲鲲2 个月前
设计模式:外观模式 Facade
设计模式·外观模式
我爱吃菠 菜2 个月前
手撕设计模式——智能家居之外观模式
设计模式·智能家居·外观模式