当前位置:编程学习 > python >>

外观模式,python语言实现

 

基本说明:外观模式不改变原有系统的结构,通过组建外观类提供对外交互的复杂工作。

                  今天上班老板交代两项工作:1.安排人扫雪。2.安派人准备接待参观考察团

                   公司原有的机构共三个部门A,B,C

                  为了完成老板安排的任务,我只好充当外观类,安排A,C部门扫雪(雪很大,需要两个部门),安排B部门接待参观(B部门姐姐,妹妹多能营造氛围)

[python]
# -*- coding: utf-8 -*- 
 
####################################################### 
#  
# Facade.py 
# Python implementation of the Class client 
# Generated by Enterprise Architect 
# Created on:      12-十二月-2012 10:52:19 
# Original author: zjm 
#  
####################################################### 
 
 
 
from __future__ import division 
from __future__ import print_function 
from __future__ import unicode_literals 
from future_builtins import * 
     
 
 
class Department(object): 
    """This class (a) implements subsystem functionality, (b) handles work assigned by
    the Facade object, and (c) keeps no reference to the facade.
    """ 
    def __init__(self, name="None"): 
        self.name=name 
        pass 
 
    def Operation(self): 
        print(self.name+ " "+"does this work") 
        pass 
 
class DepartmentA(Department): 
    """This class (a) implements subsystem functionality, (b) handles work assigned by
    the Facade object, and (c) keeps no reference to the facade.
    """ 
    def __init__(self, name="DepartmentA"): 
        super(DepartmentA,self).__init__(name) 
        pass 
 
class DepartmentB(Department): 
    """This class (a) implements subsystem functionality, (b) handles work assigned by
    the Facade object, and (c) keeps no reference to the facade.
    """ 
    def __init__(self, name="DepartmentB"): 
        super(DepartmentB,self).__init__(name) 
        pass 
 
class DepartmentC(Department): 
    """This class (a) implements subsystem functionality, (b) handles work assigned by
    the Facade object, and (c) keeps no reference to the facade.
    """ 
    def __init__(self, name="DepartmentC"): 
        super(DepartmentC,self).__init__(name) 
        pass 
 
class Facade(object): 
    """This class (a) knows which subsystem classes are responsible for a request, and
    (b) delegates client requests to appropriate subsystem objects.
    """ 
    m_DepartmentA= DepartmentA() 
    m_DepartmentB= DepartmentB() 
    m_DepartmentC= DepartmentC()     
    def __init__(self): 
        self.m_DepartmentA= DepartmentA() 
        self.m_DepartmentB= DepartmentB() 
        self.m_DepartmentC= DepartmentC() 
     
     
 
    def CleanSnow(self): 
        print("CleanSnow:") 
        self.m_DepartmentA.Operation() 
        self.m_DepartmentC.Operation()         
         
        pass 
 
    def ReceiveVisit(self): 
        print("ReceiveVisit:") 
        self.m_DepartmentB.Operation()         
        pass 
 
#客户端(老板)     
if(__name__=="__main__"):     
     
    class client: 
        m_Facade= Facade() 
        m_Facade.CleanSnow() 
        m_Facade.ReceiveVisit() 
     
 

补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,