桥接模式(python)
来源:互联网 发布:python爬虫赚钱收入 编辑:程序博客网 时间:2024/05/01 03:56
桥接模式:将系统抽象部分与它的实现部分分离,使它们可以独立地变化。
类图:
由于目标系统存在多个角度的分类,每一种分类都会有多种变化,那么就可以把多角度分离出来,让它们独立变化,减少它们之间的耦合。
#encoding=utf-8##by panda#桥接模式def printInfo(info): print unicode(info, 'utf-8').encode('gbk')#抽象类:手机品牌class HandsetBrand(): soft = None def SetHandsetSoft(self, soft): self.soft = soft def Run(self): pass #具体抽象类:手机品牌1class HandsetBrand1(HandsetBrand): def Run(self): printInfo('手机品牌1:') self.soft.Run()#具体抽象类:手机品牌2class HandsetBrand2(HandsetBrand): def Run(self): printInfo('手机品牌2:') self.soft.Run() #功能类:手机软件class HandsetSoft(): def Run(self): pass#具体功能类:游戏 class HandsetGame(HandsetSoft): def Run(self): printInfo('运行手机游戏') #具体功能类:通讯录 class HandsetAddressList(HandsetSoft): def Run(self): printInfo('运行手机通信录')def clientUI(): h1 = HandsetBrand1() h1.SetHandsetSoft(HandsetAddressList()) h1.Run() h1.SetHandsetSoft(HandsetGame()) h1.Run() h2 = HandsetBrand2() h2.SetHandsetSoft(HandsetAddressList()) h2.Run() h2.SetHandsetSoft(HandsetGame()) h2.Run() returnif __name__ == '__main__': clientUI();
类图:
- 桥接模式(python)
- python设计模式之桥接模式
- Python设计模式(四)【桥接模式】
- Python设计模式-桥接模式
- python设计模式之桥接模式
- 桥接模式(python)
- 设计模式十一(桥接模式,python 语言实现)
- Python设计模式——桥接模式
- Python的结构型设计模式之桥接模式
- 设计模式之桥接模式Python实现
- python设计模(桥接模式)
- python设计模式-工厂模式
- Python设计模式-代理模式
- Python设计模式-适配器模式
- Python设计模式-观察者模式
- Python设计模式-外观模式
- Python设计模式-策略模式
- Python设计模式-命令模式
- 文件版本控制工具SVN-Client简要教程
- 用递归的方法判断一个数组是否为递增数组
- 面试解惑-排列与组合的实现
- C指针2
- QMessageBox 显示文字对齐的实现
- 桥接模式(python)
- 汇编基础知识
- 【*】第三题:收费站(提高组第一试2011年10月21日)(2011年NOIP冲刺模拟试题)(
- 人生
- 在sql server数据库中快速删除记录,清空表
- 程序员高手是怎样炼成的
- 冒泡、快速、归并排序课程设计
- Android开发位置说明
- 100个Google搜索技巧–应用网站资源寻找