装饰模式(python)
来源:互联网 发布:淘宝刷単平台 编辑:程序博客网 时间:2024/09/21 06:42
"""装饰模式:在不修改原有功能的基础上很容易的添加新的功能新功能的添加不影响原有功能的使用能够把核心功能和装饰功能分开,去除装饰功能的重复逻辑"""from abc import ABCMetafrom abc import abstractmethodclass Human(object): __metaclass__ = ABCMeta def __init__(self, name=None): if name: self.name = name @abstractmethod def show(self): passclass Chinese(Human): def __init__(self, name): super(Chinese, self).__init__(name) def show(self): print(self.name)class Clothes(Human): def __init__(self): super(Clothes, self).__init__() self.people = None def get_people(self, people): self.people = people def show(self): self.people.show()class Hat(Clothes): def __init__(self): super(Hat, self).__init__() def show(self): super(Hat, self).show() # self.people.show() print("Hat")class Shoes(Clothes): def __init__(self): super(Shoes, self).__init__() def show(self): super(Shoes, self).show() print("Shoes")if __name__ == '__main__': chinese = Chinese("zzh") chinese.show() print("") hat = Hat() hat.get_people(chinese) hat.show() print("") shoes = Shoes() shoes.get_people(hat) shoes.show() print("") chinese.show()
0 0
- 装饰模式(python)
- 装饰模式(python)
- 装饰模式(python版)
- 【Python学习日记】【设计模式】装饰器(装饰模式)
- 设计模式:装饰者模式(Python)
- Python中的Decorator(装饰器)模式
- Python和Decorator(装饰器)模式
- 装饰模式和python装饰器
- 设计模式之python版(三)--装饰模式
- 设计模式四(装饰模式,采用python 实现)
- 大话设计模式(Python版)--装饰器模式
- Python设计模式——装饰模式(Decorator)
- Python-装饰器;Decorator模式
- python之装饰器模式
- python基础---装饰器模式
- python设计模式之装饰器模式
- Python设计模式(八)【装饰器模式】
- Python设计模式-装饰器模式
- Kafka入门经典教程
- 基于OGG的Oracle与Hadoop集群准实时同步介绍
- asyncio学习(1)
- 安卓混淆异常 transformClassesAndResourcesWithProguardForRelease
- Java WEB 向客户端返回http状态302
- 装饰模式(python)
- jQuery简洁大方的登录页面模板
- 前端调试错误
- Proposition 2.1(Post-Processing)
- 把文件夹开放所有权限
- RHCSA
- GTK 缓冲区
- spring <context:component-scan>使用说明(转)
- Oracle数据库文件坏块损坏的恢复方法