生活赋予我们一种巨大的和无限高贵的礼品,这就是青春:充满着力量,充满着期待志愿,充满着求知和斗争的志向,充满着希望信心和青春。
"""代理模式"""
import time
class SalesManager:
def talk(self):
print("销售经理准备谈")
class Proxy:
def __init__(self):
self.busy = 'No'
self.sales = None
def talk(self):
print("代理检查销售经理的可访问性")
if self.busy == 'No':
self.sales = SalesManager()
time.sleep(0.1)
self.sales.talk()
else:
time.sleep(0.1)
print("销售经理正忙")
class NoTalkProxy(Proxy):
def talk(self):
print("代理检查销售经理的可访问性")
time.sleep(0.1)
print("该销售经理也不会跟你说话不论他/她是否正忙")
if __name__ == '__main__':
p = Proxy()
p.talk()
p.busy = 'Yes'
p.talk()
p = NoTalkProxy()
p.talk()
p.busy = 'Yes'
p.talk()
运行结果如图:
![这里写图片描述](https://img-blog.csdn.net/20160829235328129)