大胖的部落格

Just a note

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  112 随笔 :: 0 文章 :: 3 评论 :: 0 Trackbacks
Fasade模式提供一个简单接口,调用复杂的子系统接口。


#include <iostream>

using namespace std;


class Printer
{
public:
    
void Print() {cout<<"Print"<<endl;}
}
;

class Typer
{
public:
    
void Type() {cout<<"Type"<<endl;}
}
;

class Writer
{
public:
    
void Write() {cout<<"Write"<<endl;}
}
;

//Fasade
class Fasade
{
public:
    Fasade(Printer
* p, Typer* t, Writer* w)
        :pp(p),pt(t),pw(w)
{}
    
~Fasade()
    
{
        delete pp;
        delete pt;
        delete pw;
    }

    
//提供一个一致接口
    void Work() 
    
{
        pp
->Print();
        pt
->Type();
        pw
->Write();
    }

private:
    Printer
*    pp;
    Typer
*        pt;
    Writer
*        pw;
}
;

int main()
{
    Fasade 
*pf = new Fasade(new Printer, new Typer, new Writer);
    pf
->Work();
    delete pf;

    
return 0;
}
posted on 2009-06-09 16:14 大胖 阅读(124) 评论(0)  编辑 收藏 引用 所属分类: Design Pattern

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理