@@ -21,6 +21,9 @@ class Subject:
21
21
As mentioned in the document, interfaces of both RealSubject and Proxy should
22
22
be the same, because the client should be able to use RealSubject or Proxy with
23
23
no code change.
24
+
25
+ Not all times this interface is necessary. The point is the client should be
26
+ able to use RealSubject or Proxy interchangeably with no change in code.
24
27
"""
25
28
26
29
def do_the_job (self , user ):
@@ -54,15 +57,32 @@ def do_the_job(self, user):
54
57
print (f'[log] I can do the job just for `admins`.' )
55
58
56
59
60
+ def client (job_doer , user ):
61
+ job_doer .do_the_job (user )
62
+
57
63
if __name__ == '__main__' :
58
64
proxy = Proxy ()
59
- proxy .do_the_job ('admin' )
60
- proxy .do_the_job ('anonymous' )
65
+ real_subject = RealSubject ()
66
+
67
+ print ('# doing the job with proxy:' )
68
+ client (proxy , 'admin' )
69
+ client (proxy , 'anonymous' )
70
+
71
+ print ()
72
+
73
+ print ('# doing the job with real-subject:' )
74
+ client (real_subject , 'admin' )
75
+ client (real_subject , 'anonymous' )
61
76
62
77
63
78
OUTPUT = """
79
+ # doing the job with proxy:
64
80
[log] Doing the job for admin is requested.
65
81
> I am doing the job for admin
66
82
[log] Doing the job for anonymous is requested.
67
83
[log] I can do the job just for `admins`.
84
+
85
+ # doing the job with real-subject:
86
+ > I am doing the job for admin
87
+ > I am doing the job for anonymous
68
88
""" # noqa
0 commit comments