设计模式 之 《外观模式》

 

#ifndef __FACADE_MODEL__
#define __FACADE_MODEL__

#include <iostream>
using namespace std;

//GOOD:为子系统的一组接口提供一个一致的界面。使用户使用起来更加方便。

class SubSystemOne
{
public:
    void methodOne(){ cout<<"One"<<endl; }
};

class SubSystemTwo
{
public:
    void methodTwo(){ cout<<"Two"<<endl; }
};

class SubSystemThree
{
public:
    void methodThree(){ cout<<"Three"<<endl; }
};

class Facade
{
public:
    Facade()
    {
        sub1 = new SubSystemOne();
        sub2 = new SubSystemTwo();
        sub3 = new SubSystemThree();
    }

    ~Facade()
    {
        delete sub1;
        delete sub2;
        delete sub3;
    }

    void facadeMethod()
    {
        sub1->methodOne();
        sub2->methodTwo();
        sub3->methodThree();
    }

private:
    SubSystemOne* sub1;
    SubSystemTwo* sub2;
    SubSystemThree* sub3;
};

#endif //__FACADE_MODEL__

/*
#include "FacadeModel.h"
int _tmain(int argc, _TCHAR* argv[])
{
    Facade* facade = new Facade();
    facade->facadeMethod();

    return 0;
}
*/

 

posted @ 2013-11-03 16:43  解放1949  阅读(110)  评论(0编辑  收藏  举报