桥接模式
来源:互联网 发布:天池大数据2017 编辑:程序博客网 时间:2024/05/16 07:50
#include <iostream.h>
//桥接模式
//存在一种分类,其中有不同的个体,这些个体是互斥的
//但这些个体将要表现出基本一致的行为
//由于这些个体的互斥性,这些行为在通常意义上将表现出个体唯一性
//若使用工厂模式,这使得这些个体增加,整个体系会增加更剧烈
//由于考虑将这些个体的行为单独提取出,向外提供统一的接口
//这些行为作为对象将聚合到个体内部,从外界看,对象具有对个体认知的唯一性
class Action //行为的统一抽象
{
public:
Action(){}
~Action(){}
public:
virtual void show() = 0;
};
class Book : public Action
{
public:
Book(){}
~Book(){}
public:
virtual void show()
{
cout << "使用阅读器" << endl;
}
};
class Game : public Action
{
public:
Game(){}
~Game(){}
public:
virtual void show()
{
cout << "使用游戏功能" << endl;
}
};
class mobile //手机类 具有普遍性
{
protected:
Action *act; //行为是装载进入的 可随时加入和卸出
public:
mobile(){}
~mobile(){}
public:
void SetAc(Action *act)
{
this->act = act;
}
void SetAcNull()
{
if(NULL != act)
delete act;
act = NULL;
}
virtual void show() = 0;
};
class Nmobile : public mobile //同Mmobile互斥
{
public:
Nmobile(){}
~Nmobile(){}
public:
void show()
{
this->act->show();
}
};
class Mmobile : public mobile
{
public:
Mmobile(){}
~Mmobile(){}
public:
void show()
{
this->act->show();
}
};
void main()
{
mobile *Nm = new Nmobile();
Action *act = new Game();
Nm->SetAc(act);
Nm->show();
Nm->SetAcNull();
mobile *Mm = new Mmobile();
act = new Game();
Mm->SetAc(act);
Mm->show();
Mm->SetAcNull();
}
- 设计模式:适配器模式,桥接模式
- 设计模式----桥接模式
- 设计模式---桥接模式
- 结构性模式-桥接模式
- 设计模式:桥接模式
- 设计模式 桥接模式
- 设计模式 - 桥接模式
- 设计模式--桥接模式
- 设计模式--桥接模式
- 设计模式 - 桥接模式
- 设计模式-桥接模式
- 设计模式 - 桥接模式
- 设计模式 - 桥接模式
- 【设计模式-桥接模式】
- 设计模式:桥接模式
- 【设计模式】----桥接模式
- 【设计模式】桥接模式
- 设计模式--桥接模式
- nand write.e 所查到得资料
- java问题集锦
- 关于sql 中导入数据时的自动增长列转换为一般列,导入后转换为自动增长列
- android内存管理的原理--进程管理
- 广州开建世界最大足球学校 首期建有76块球场
- 桥接模式
- android 常用权限备份
- 架构师之我见
- ExtJS之数据验证
- 开放自己的Apache给别人访问
- sql练习题
- C语言中C文件与h头文件的关系
- BOOL与bool的区别