版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、,指导老师:李新 日期:2012.9.26,程序设计方法学 桥接设计模式,主要内容:,模式动机与定义 模式结构与分析 模式实例与解析 小结, 模式动机 假设现在有一个M品牌和一个N品牌的手机, 它们都有游戏和通讯录两个小软件。 该如何设计: 使客户端可以任意的调用 两个品牌的小软件?,方案一:先建立一个父类“手机品牌”,下有“手机品牌M”和“手机品牌N”,每个子类各有“通讯录”和“游戏”子类。 类图:,方案二:先建立一个父类“手机软件”,下有“游戏”和“通讯录”,每个子类各有“手机品牌M”和“手机品牌N”子类。 类图:,方案一的代码,类的定义: #include using namespace
2、 std; class Cellphone public: virtual void Run() = 0; class CellphoneBrandM : public Cellphone public: virtual void Run() coutdevelop the cellphonebrand_m endl; ; class CellphoneBrandN : public Cellphone public: virtual void Run() coutdevelop the cellphonebrand_n endl; ; class CellphoneGame_M : publ
3、ic CellphoneBrandM public: virtual void Run() cout run the cellphone_game_ms game endl; ; class CellphoneAddressList_M : public CellphoneBrandM public: virtual void Run() cout run the cellphone_addresslist_ms game endl; ; class CellphoneGame_N : public CellphoneBrandN public: virtual void Run() cout
4、 run the cellphone_game_ns game endl; ; class CellphoneAddressList_N : public CellphoneBrandN public: virtual void Run() cout run the cellphone_addresslist_ns game endl; ;,主程序: void main() Cellphone* cellm = new CellphoneBrandM(); cellm-Run(); CellphoneBrandM* brandm1= new CellphoneGame_M(); brandm1
5、-Run(); CellphoneBrandM* brandm2= new CellphoneAddressList_M(); brandm2-Run(); Cellphone* celln = new CellphoneBrandN(); celln-Run(); CellphoneBrandN* brandn1= new CellphoneGame_N(); brandn1-Run(); CellphoneBrandN* brandn2= new CellphoneAddressList_N(); brandn2-Run(); ,. 模式定义,桥接模式(Bridge Pattern):将抽
6、象部分与它的实现部分分离,使它们都可以独立地变化。它是一种对象结构型模式。 1.什么叫抽象与它的实现分离? 2.实现是什么意思?,.桥接模式结构: 结构图:,(聚合),类的定义: #include #include #include using namespace std; class CellphoneSoft /手机软件 public: virtual void Run()=0; class CellphoneGame : public CellphoneSoft /游戏软件 public: virtual void Run() coutRun(); ; class CellphoneBr
7、andN : public CellphoneBrand /N品牌 public: virtual void Run()m_soft-Run(); ;,主程序: int main() CellphoneBrand *brand; brand = new CellphoneBrandM(); brand-SetCellphoneSoft(new CellphoneGame(); brand-Run(); brand-SetCellphoneSoft(new CellphoneAddressList(); brand-Run(); brand = new CellphoneBrandN(); brand-SetCellphoneSoft(new CellphoneGame(); brand-Run(); brand-SetCellphoneSoft(new CellphoneAddressList(); brand-Run(); return 0; ,使用桥接设计模式后的代码:,.模式实例与解析,.小结 *桥接模式的优点: 将实现给予解耦,让它和界面之间不再永久绑定。 抽象和实现可以独立扩展,不会影响到对方。 对于“
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 道路危化品运输车辆安全管控方案
- 医院智慧病房系统施工方案
- 采煤机维护工安全操作规程
- 布加综合征抗凝出血风险定期监测标准共识
- P2P测试用例面试真题及详细答案(实操版)
- 皮肌炎运动时机个体化评估共识
- 心电监护技术操作理论考试试题及答案
- 疲劳驾驶预警及安全干预方案
- 椎管内肿瘤诊疗专家共识(2025版)
- 2026年甘肃事业单位招聘考试(护林员)历年参考题库含答案
- 冬季矿山五防安全培训课件
- 骨折牵引护理查房
- 小儿推拿进修总结汇报
- 2025年上海市公务员《行政职业能力测验(B卷)》试题(网友回忆版)
- 消防工程施工图识图试题及答案
- 向往混声合唱谱【简谱】
- 解码国家安全-知到答案、智慧树答案
- GA/T 2015-2023芬太尼类药物专用智能柜通用技术规范
- 《小猴子下山》公开课
- 第五章第二节园林的构图和意境02
- 服装造型设计课件
评论
0/150
提交评论