设计模式8:外观模式

外观模式,应该是我们写程序的最容易想到的方法(虽说我们再不经意间使用的时候,并不知道这个方法叫外观模式),就是为一些子功能提供一个公共接口,所以并不打算过多罗嗦。

直接上代码

#include<iostream>
using namespace std;

class Sub1 {
public:
    void Show() {
        cout << "sub system method one" << endl;
    }
};

class Sub2 {
public:
    void Show() {
        cout << "sub system method two" << endl;
    }
};

class Sub3 {
public:
    void Show() {
        cout << "sub system method three" << endl;
    }
};

class Facade {
public:
    void ShowA() {
        cout << "method A: " << endl;
        sub1.Show();
        sub2.Show();
        sub3.Show();
    }

    void ShowB() {
        cout << "method B: " << endl;
        sub1.Show();
        sub2.Show();
    }
private:
    Sub1 sub1;
    Sub2 sub2;
    Sub3 sub3;
};

int main()
{
    Facade facade;
    facade.ShowA();
    facade.ShowB();
    return 0;
}
原文地址:https://www.cnblogs.com/457220157-FTD/p/4056060.html