基本原理请参考相关书籍。
基本说明:
公司总体上分为市场部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()