设计模式十(适配器模式,python语言实现)

基本原理请参考相关书籍。

基本说明:

公司总体上分为市场部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()      

    
        
    
    


    


      
    
   


   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值