设计模式四(装饰模式,采用python 实现)
2012-12-09 13:16
696 查看
装饰模式原理请随便找书看一下,这里直接给例子:
生产一把刀需要两个工序,工序一和工序二
Process:生产
Component:原料(生产刀具的原材料是棒料 bar)
Procedure:生产刀具工序
FirstProcedure:工序一
SecondProcedure:工序二
生产一把刀需要两个工序,工序一和工序二
Process:生产
Component:原料(生产刀具的原材料是棒料 bar)
Procedure:生产刀具工序
FirstProcedure:工序一
SecondProcedure:工序二
from __future__ import division from __future__ import print_function from __future__ import unicode_literals from future_builtins import * import sys class Process(object): def __init__(self): super(Process,self).__init__() pass def make(self): pass class Component(Process): def __init__(self): super(Component,self).__init__() pass def make(self): print("bar") pass pass class Procedure(Process): component=Process() def __init__(self,comp): super(Procedure,self).__init__() self.component=comp pass def make(self): print('procedure') pass pass class FirstProcedure(Procedure): def __init__(self,component): super(FirstProcedure,self).__init__(component) pass def make(self): self.component.make() print('firs procedure') pass pass class SecondProcedure(Procedure): def __init__(self,component): super(SecondProcedure,self).__init__(component) pass def make(self): self.component.make() print('second procedure') pass pass #客户端 if(__name__=="__main__"): component=Component() first=FirstProcedure(component) second=SecondProcedure(first) second.make()
相关文章推荐
- 设计模式六(建造者模式,采用python实现)
- 设计模式一(简单工厂,采用python实现)
- 设计模式二(策略模式,采用python实现)
- 设计模式C++实现--装饰模式
- Head First 设计模式——策略模式(Strategy Pattern)——Python实现
- Head First 设计模式——观察者模式(Observer Pattern)——Python实现(1)
- Head First 设计模式——装饰器(Decorator Pattern)——Python实现
- J2SE中 装饰设计模式之用自定义类去实现BufferedReader类的功能
- python 设计模式实现
- 流畅的python 第六章: 使用一等函数实现设计模式
- 23种设计模式之python实现--Memento模式
- 设计模式之装饰模式Java实现
- 设计模式实现(三)---装饰模式
- 23种设计模式之python实现--工厂方法
- 【设计模式 】一 简单工厂模式 (python实现)
- [python实现设计模式]-3.简单工厂模式-触宝开放平台
- Head First 设计模式——观察者模式(Observer Pattern)——Python实现(2)
- 设计模式C++实现(11)——装饰模式
- <读书笔记> Thinking in python (Python 设计模式) 1. Singlton的c++与python的实现
- 设计模式之python版(三)--装饰模式