门面模式 Facade

门面模式,是指提供一个统一的接口去访问多个子系统的多个不同的接口,它为子系统中的一组接口提供一个统一的高层接口。使用子系统更容易使用。

 

例子如下,完成program任务,内部完成 code compile run任务

#include "iostream"
using namespace std;
class code{
public:
    void active(){
        cout<<"finish code"<<endl;
    }
};

class compile{
public:
    void active(){
        cout<<"finish compile"<<endl;
    }
};

class run{
public:
    void active(){
        cout<<"finish run"<<endl;
    }
};

class program{
public:
    program(){
        pcode = new code;
        pcompile = new compile;
        prun = new run;
    }
    ~program(){
        delete pcode;
        delete pcompile;
        delete prun;
    }

    void dotask(){
        pcode->active();
        pcompile->active();
        prun->active();

        cout<<"the task to program is finished"<<endl;
    }

private:
    code * pcode;
    compile * pcompile;
    run * prun;
};

int main(int argc, char* argv[])
{
    program * pprogram = new program;
    pprogram->dotask();
    return 0;
}

 

posted @ 2015-07-09 22:05  朽木可雕否  阅读(111)  评论(0编辑  收藏  举报