您的位置:首页 > 编程语言 > C语言/C++

C++实现装饰者模式

2012-11-06 16:57 281 查看
/*
外观模式:为子系统的一组接口提供一个一致的界面,
此模式定义了一个高层接口,这个接口使得子系统更容易使用
*/

#include <iostream>
using namespace std;

class TestA
{
public:
void display_a()
{
cout<<"display a..."<<endl;
}
};

class TestB
{
public:
void display_b()
{
cout<<"display b..."<<endl;
}
};

class Facade
{
TestA *testa;
TestB *testb;

public:
Facade()
{
testa = new TestA();
testb = new TestB();
}
~Facade()
{
delete testa;
delete testb;
}

void MethodA()
{
testa->display_a();
testb->display_b();
}
};

int main()
{
Facade *facade = new Facade();

facade->MethodA();

system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: