设计模式十(适配器模式,python语言实现)
2012-12-11 15:29
796 查看
基本原理请参考相关书籍。
基本说明:
公司总体上分为市场部MarketDepartment和生产部ProductDepartment
市场部有分为:
铣刀市场部:MillMD
钻头市场部:DirllMD
生产部又分为:
铣刀生成部:MillPD
钻头生产部:DrillPD
客户通过市场部下订单,市场部接到订单通过生产部门完成订单。
基本说明:
公司总体上分为市场部MarketDepartment和生产部ProductDepartment
市场部有分为:
铣刀市场部:MillMD
钻头市场部:DirllMD
生产部又分为:
铣刀生成部:MillPD
钻头生产部:DrillPD
客户通过市场部下订单,市场部接到订单通过生产部门完成订单。
#源代码
# -*- coding: utf-8 -*- ####################################################### # # adaptor.py # Python implementation of the Class Client # Generated by Enterprise Architect # Created on: 11-十二月-2012 15:00:59 # ####################################################### from __future__ import division from __future__ import print_function from __future__ import unicode_literals from future_builtins import * class ProductDepartment(object): """This class defines an existing interface that needs adapting. """ def make(self): pass class DrillPD(ProductDepartment): """This class defines an existing interface that needs adapting. """ def make(self): print("make drills") pass class MillPD(ProductDepartment): """This class defines an existing interface that needs adapting. """ def make(self): print("make mills") pass class MarketDepartment(object): """This class defines the domain-specific interface that Client uses. """ def Request(): pass class MillMD(MarketDepartment): """This class adapts the interface of Adaptee to the Target interface. """ m_MillPD= MillPD() def Request(self): m_MillPD=MillPD() m_MillPD.make() pass class DrillMD(MarketDepartment): """This class adapts the interface of Adaptee to the Target interface. """ m_DrillPD= DrillPD() def Request(self): # adaptee->SpecificRequest() m_DrillPD=DrillPD() m_DrillPD.make() pass #客户端 if(__name__=="__main__"): class Client(object): """This class collaborates with objects conforming to the Target interface. """ m_MarketDepartment= MarketDepartment() def __init__(self): self.m_MarketDepartment=None pass def SetOrder(self,department): self.m_MarketDepartment=department pass def GetOrder(self): self.m_MarketDepartment.Request() pass pass client= Client() client.SetOrder(MillMD()) client.GetOrder() client.SetOrder(DrillMD()) client.GetOrder()
相关文章推荐
- 研磨设计模式解析及python代码实现——(三)适配器模式(Adapter)
- 设计模式十四(享元模式flyweight,python语言实现)
- 设计模式十三(外观模式,python语言实现)
- java语言实现结构型设计模式—适配器模式
- 设计模式九(单例模式,python语言实现)
- 设计模式十八(观察者模式,python语言实现)
- 设计模式八(原型模式,python语言实现)
- 设计模式十二(组合模式,python语言实现)
- 设计模式十九(中介者模式,python语言实现)
- 设计模式十一(桥接模式,python 语言实现)
- 设计模式十七(状态模式,python语言实现)
- [python实现设计模式]-2.模板方法模式---把大象关进冰箱.
- 23种设计模式之python实现--解释器模式
- 设计模式C++实现——适配器模式
- 设计模式----适配器模式UML和实现代码(5个必须掌握的设计模式)
- [python实现设计模式]-1. 单例模式
- 设计模式-适配器模式-adapter-python
- 23种设计模式之python实现--Adapter模式
- 使用Python语言写一个简单的KMP模式匹配算法实现
- python 设计模式实现