Skip to content

Commit 138e5c5

Browse files
modified the proxy.py. This modification shows that proxy can be used to block some operations of the other objects.
1 parent 54e2674 commit 138e5c5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

proxy.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class SalesManager:
8-
98
def work(self):
109
print("Sales Manager working...")
1110

@@ -14,7 +13,6 @@ def talk(self):
1413

1514

1615
class Proxy:
17-
1816
def __init__(self):
1917
self.busy = 'No'
2018
self.sales = None
@@ -30,14 +28,32 @@ def work(self):
3028
print("Sales Manager is busy")
3129

3230

31+
class NoTalkProxy(Proxy):
32+
def __init__(self):
33+
Proxy.__init__(self)
34+
35+
def work(self):
36+
print("Proxy checking for Sales Manager availability")
37+
time.sleep(2)
38+
print("This Sales Manager will not talk to you whether he/she is busy or not")
39+
40+
3341
if __name__ == '__main__':
3442
p = Proxy()
3543
p.work()
3644
p.busy = 'Yes'
3745
p.work()
46+
p = NoTalkProxy()
47+
p.work()
48+
p.busy = 'Yse'
49+
p.work()
3850

3951
### OUTPUT ###
4052
# Proxy checking for Sales Manager availability
4153
# Sales Manager ready to talk
4254
# Proxy checking for Sales Manager availability
4355
# Sales Manager is busy
56+
# Proxy checking for Sales Manager availability
57+
# This Sales Manager will not talk to you whether he/she is busy or not
58+
# Proxy checking for Sales Manager availability
59+
# This Sales Manager will not talk to you whether he/she is busy or not

0 commit comments

Comments
 (0)