外观模式

外观模式

 

模式说明

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

模式结构图

程序示例

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

代码:

复制代码
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值