• 外观模式


    模式说明

    所谓外观模式就是提供一个统一的接口,用来访问子系统中的一群接口。

    模式结构图

    程序示例

    说明:灯光、荧屏、空调、电视一键开启、关闭

    代码:

    class Light(object):
        def on(self):
            print 'light turn on'
        def off(self):
            print 'light turn off'
    
    class Screen(object):
        def on(self):
            print 'screen turn on'
        def off(self):
            print 'screen turn off'
    
    class AirConditioner(object):
        def on(self):
            print 'AirConditioner turn on'
        def off(self):
            print 'AirConditioner turn off'
    
    class TV(object):
        def on(self):
            print 'TV turn on'
        def off(self):
            print 'TV turn off'
    
    class Facade(object):
        """description of class"""
        light=Light()
        screen=Screen()
        airconditioner = AirConditioner()
        tv=TV()
        def on(self):
            print 'one key all on'
            self.light.on()
            self.screen.on()
            self.airconditioner.on()
            self.tv.on()
            
        def off(self):
            print 'one key all off'
            self.light.off()
            self.screen.off()
            self.airconditioner.off()
            self.tv.off()
    
    if __name__=='__main__':
        facade=Facade()
        facade.on()
        facade.off()

    运行结果:

    参考来源:

    http://www.cnblogs.com/chenssy/p/3679190.html

    http://www.cnblogs.com/wuyuegb2312/archive/2013/04/09/3008320.html

    http://www.cnblogs.com/Terrylee/archive/2006/07/17/334911.html

  • 相关阅读:
    vue项目实现路由按需加载
    常用的meta标签
    聊聊https
    Centos 7 忘记root密码修改方法
    find常用命令
    linux上的mysql忘记密码
    kaill 安装zenmap软件
    selenium.common.exceptions.WebDriverException: Message: 'chromedriver'解决
    centos7 开机执行脚本或者命令
    Linux下载常用命令
  • 原文地址:https://www.cnblogs.com/cotton/p/3934963.html
Copyright © 2020-2023  润新知