设计模式---外观模式

来源:互联网 发布:怎么识谱古筝知乎 编辑:程序博客网 时间:2024/05/22 04:45

外观模式

为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用。


#include<iostream>


using namespace std;


class SubSystemOne
{
    public:
        void MethodOne()
        {
            cout<<"system method 1 "<<endl;
        }
};

class SubSystemTwo
{
    public:
        void MethodTwo()
        {
            cout<<"system method 2 "<<endl;
        }
};


class SubSystemThree
{
    public:
        void MethodThree()
        {
            cout<<"system method 3 "<<endl;
        }
};

class SubSystemFour
{
    public:
        void MethodFour()
        {
            cout<<"system method 4 "<<endl;
        }
};

class Facade
{
    SubSystemOne *one;
    SubSystemTwo *two;
    SubSystemThree *three;
    SubSystemFour *four;

    public:
        Facade()
        {
            one = new SubSystemOne();
            two = new SubSystemTwo();
            three = new SubSystemThree();
            four = new SubSystemFour();
        }
        void MethodA()
        {
            cout<<"method a..."<<endl;
            one->MethodOne();
            two->MethodTwo();
        }
        void MethodB()
        {
            cout<<"method b..."<<endl;
            three->MethodThree();
            four->MethodFour();
        }
};

int main()
{
    Facade *facade = new Facade();
    facade->MethodA();
    facade->MethodB();

    return  0;
}