查看: 540|回复: 4
打印 上一主题 下一主题

【设计模式玩pyBoard】8.外观模式

[复制链接] qrcode

23

主题

27

帖子

82

积分

注册会员

Rank: 2

积分
82
楼主
跳转到指定楼层
发表于 2016-6-7 10:36 AM | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
    外观模式:为一组调用提供一致的接口。
    代码:

  1. import pyb

  2. class SubSystemOne:
  3.     def MethodOne(self):
  4.         print "SubSysOne"

  5. class SubSystemTwo:
  6.     def MethodTwo(self):
  7.         print "SubSysTwo"

  8. class SubSystemThree:
  9.     def MethodThree(self):
  10.         print "SubSysThree"

  11. class SubSystemFour:
  12.     def MethodFour(self):
  13.         print "SubSysFour"


  14. class Facade:
  15.     def __init__(self):
  16.         self.one = SubSystemOne()
  17.         self.two = SubSystemTwo()
  18.         self.three = SubSystemThree()
  19.         self.four = SubSystemFour()
  20.     def MethodA(self):
  21.         print "MethodA"
  22.         self.one.MethodOne()
  23.         self.two.MethodTwo()
  24.         self.four.MethodFour()
  25.     def MethodB(self):
  26.         print "MethodB"
  27.         self.two.MethodTwo()
  28.         self.three.MethodThree()

  29. if __name__ == "__main__":
  30.     facade = Facade()
  31.     facade.MethodA()
  32.     facade.MethodB()
复制代码

        将众多的功能函数分别组成不同的组别,通过接口调用某组功能。
        黄瓜、鸡蛋、木耳、西红柿、芹菜、茄子。。。。。。,我能做出木须肉、西红柿炒鸡蛋。。。。。。
       

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表