首页 > 代码库 > 外观模式

外观模式

模式说明

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

模式结构图

程序示例

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

代码:

class Light(object):    def on(self):        print light turn on    def off(self):        print light turn offclass Screen(object):    def on(self):        print screen turn on    def off(self):        print screen turn offclass AirConditioner(object):    def on(self):        print AirConditioner turn on    def off(self):        print AirConditioner turn offclass TV(object):    def on(self):        print TV turn on    def off(self):        print TV turn offclass 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

 

外观模式