23种设计模式之python实现--Decorator模式
来源:互联网 发布:软件测试知识点总结 编辑:程序博客网 时间:2024/05/02 04:26
#理解#动态的给一个对象添加额外的职责#例子#假如有一只会叫的dog,现在让它叫的时候会张嘴#Componentclass Animal(object): def speak(self): pass#ConcreateComponentclass dog(Animal): def speak(self): print 'wangwang'#Decoratorclass Decorator(object): Component=None def speak(self): self.Component.speak()#ConcreateDecoratorclass ConcreateDecorator(Decorator): def __init__(self,Com): self.Component=Com def speak(self): self.openmouth() super(ConcreateDecorator,self).speak() def openmouth(self): print 'open mouth'#clientif __name__=='__main__': ComcreateComponent=dog() dec=ConcreateDecorator(ComcreateComponent) dec.speak()
运行如图:
0 0
- 23种设计模式之python实现--Decorator模式
- 23设计模式之装饰模式(Decorator)
- 23设计模式之装饰模式(Decorator)
- python实现Decorator模式
- 设计模式之Decorator
- 设计模式之 Decorator
- 设计模式之Decorator
- 设计模式之Decorator
- 设计模式之Decorator
- 设计模式之 decorator
- 设计模式之Decorator
- 设计模式之Decorator
- 设计模式之Decorator
- 23种设计模式之装饰模式(Decorator)
- 设计模式之---Decorator 模式
- 23种设计模式(8)--Decorator模式
- 23种设计模式之python实现
- 设计模式-装饰模式-decorator-python
- android学习篇
- 安卓经典功能组件篇1——实现界面的异步刷新
- 安装Matlab的svm工具
- 2014 阿里巴巴 数据分析师 笔试
- poj2456(贪心+二分)
- 23种设计模式之python实现--Decorator模式
- 利用mmap /dev/mem 读写Linux内存
- shell学习:显示、读取或拼接文件内容:cat命令用法
- 100个常用Linux命令
- FragmentPagerAdapter与FragmentStatePagerAdapter差异
- 数据结构与程序架构(四)
- Android标题栏的去除和全屏
- 推荐系统方法之协同过滤
- 《大型网站技术架构》读书笔记 - 网站的技术升级路线