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
相关推荐
太过平凡的小蚂蚁6 天前
外观模式:复杂系统的统一入口
外观模式
Yeniden6 天前
【设计模式】# 外观模式(Facade)大白话讲解!
java·设计模式·外观模式
杯莫停丶13 天前
设计模式之:外观模式
java·设计模式·外观模式
WaWaJie_Ngen14 天前
【设计模式】外观模式/门面模式(Facaed)
设计模式·外观模式
Meteors.17 天前
23种设计模式——外观模式(Facade Pattern)详解
设计模式·外观模式
胖虎117 天前
iOS中的设计模式(九)- 外观模式 用外观模式点一份外卖:Swift 实战讲解
设计模式·外观模式
czy878747517 天前
用C语言实现外观模式
c语言·外观模式
Deschen18 天前
设计模式-外观模式
java·设计模式·外观模式
Mr_WangAndy24 天前
C++设计模式_结构型模式_外观模式Facade
c++·设计模式·外观模式
代码萌新知1 个月前
设计模式学习(五)装饰者模式、桥接模式、外观模式
java·学习·设计模式·桥接模式·装饰器模式·外观模式