From 138e5c5690b1ca2eac979cbbd23313b7013397c0 Mon Sep 17 00:00:00 2001 From: LiVincent-Zhang Date: Sat, 18 Apr 2015 13:49:03 +0800 Subject: [PATCH 1/2] modified the proxy.py. This modification shows that proxy can be used to block some operations of the other objects. --- proxy.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/proxy.py b/proxy.py index 4c5b4cc0..390b1074 100644 --- a/proxy.py +++ b/proxy.py @@ -5,7 +5,6 @@ class SalesManager: - def work(self): print("Sales Manager working...") @@ -14,7 +13,6 @@ def talk(self): class Proxy: - def __init__(self): self.busy = 'No' self.sales = None @@ -30,14 +28,32 @@ def work(self): print("Sales Manager is busy") +class NoTalkProxy(Proxy): + def __init__(self): + Proxy.__init__(self) + + def work(self): + print("Proxy checking for Sales Manager availability") + time.sleep(2) + print("This Sales Manager will not talk to you whether he/she is busy or not") + + if __name__ == '__main__': p = Proxy() p.work() p.busy = 'Yes' p.work() + p = NoTalkProxy() + p.work() + p.busy = 'Yse' + p.work() ### OUTPUT ### # Proxy checking for Sales Manager availability # Sales Manager ready to talk # Proxy checking for Sales Manager availability # Sales Manager is busy +# Proxy checking for Sales Manager availability +# This Sales Manager will not talk to you whether he/she is busy or not +# Proxy checking for Sales Manager availability +# This Sales Manager will not talk to you whether he/she is busy or not From 58b31504907d91caf19a696302b1fa9bdf8b0e0b Mon Sep 17 00:00:00 2001 From: Livincent-Zhang Date: Wed, 22 Apr 2015 08:33:10 +0800 Subject: [PATCH 2/2] fix typo --- proxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy.py b/proxy.py index 390b1074..a60b1f53 100644 --- a/proxy.py +++ b/proxy.py @@ -45,7 +45,7 @@ def work(self): p.work() p = NoTalkProxy() p.work() - p.busy = 'Yse' + p.busy = 'Yes' p.work() ### OUTPUT ###