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

本文共 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

你可能感兴趣的文章
AcWing 超市
查看>>
洛谷 P3376 【模板】网络最大流
查看>>
洛谷 P4147 玉蟾宫
查看>>
WorkSample.Quartz
查看>>
RabbitMQTutorials.02
查看>>
WorkSample.StackExchange.Redis
查看>>
论nw.js的坑~~~感觉我所有的前端能遇到的坑都踩了一遍
查看>>
angular的开始历程
查看>>
day19生产者消费模型yield
查看>>
rsync实现远程同步
查看>>
APP爬虫(1)想学新语言,又没有动力,怎么办?
查看>>
请假过来面试,没有被录用,总不能让我一点收获都没有吧
查看>>
APP爬虫(2)把小姐姐的图片down下来
查看>>
OAuth2.0授权登录
查看>>
ECU嵌入式软件开发基础之大小端知识
查看>>
2019春季第一周心得总结
查看>>
结构体 自引用
查看>>
css3 transform 的奇妙
查看>>
ios开发版证书与企业证书相关文件申请安装及其使用方法
查看>>
二分答案 [Usaco2014 Mar]Sabotage
查看>>