博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
外观模式
阅读量:4704 次
发布时间:2019-06-10

本文共 1305 字,大约阅读时间需要 4 分钟。

 

模式说明

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

模式结构图

程序示例

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

代码:

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

转载于:https://www.cnblogs.com/Siny0/p/11155943.html

你可能感兴趣的文章
UILayer
查看>>
复杂对象写入文件
查看>>
k8s-高级调度方式-二十一
查看>>
[HDU3555]Bomb
查看>>
基于dubbo的分布式系统(一)安装docker
查看>>
Recursion
查看>>
66. Plus One
查看>>
COMP30023 Computer Systems 2019
查看>>
CSS选择器分类
查看>>
Kali学习笔记39:SQL手工注入(1)
查看>>
C# MD5加密
查看>>
Codeforces Round #329 (Div. 2)D LCA+并查集路径压缩
查看>>
移动应用开发测试工具Bugtags集成和使用教程
查看>>
Java GC、新生代、老年代
查看>>
Liferay 6.2 改造系列之十一:默认关闭CDN动态资源
查看>>
多线程
查看>>
折线切割平面
查看>>
获取当前路径下的所有文件路径 :listFiles
查看>>
图像形态学及更通用的形态学的原理及细节汇总
查看>>
linux开启coredump的3种方法
查看>>