|
代理模式:为其他对象提供代理机制来控制访问这个对象。
代码:
- import pyb
- class Interface:
- def Request(self):
- pyb.LED(1).on()
- pyb.delay(1000)
- pyb.LED(1).off()
- pyb.delay(1000)
-
- class Subject(Interface):
- def Request(self):
- pyb.LED(2).on()
- pyb.delay(1000)
- pyb.LED(2).off()
- pyb.delay(1000)
-
- class Proxy(Interface):
- def Request(self):
- self.obj = Subject()
- self.obj.Request()
-
- if __name__ == "__main__":
- led = Proxy()
- led.Request()
复制代码
通过Proxy类来实现对Interface类的访问,但其实Interface类的Request函数并没有执行。看效果是这样,不知道理解的对不对。
|
|