@@ -21,6 +21,9 @@ class Subject:
2121 As mentioned in the document, interfaces of both RealSubject and Proxy should
2222 be the same, because the client should be able to use RealSubject or Proxy with
2323 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.
2427 """
2528
2629 def do_the_job (self , user ):
@@ -54,15 +57,32 @@ def do_the_job(self, user):
5457 print (f'[log] I can do the job just for `admins`.' )
5558
5659
60+ def client (job_doer , user ):
61+ job_doer .do_the_job (user )
62+
5763if __name__ == '__main__' :
5864 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' )
6176
6277
6378OUTPUT = """
79+ # doing the job with proxy:
6480[log] Doing the job for admin is requested.
6581> I am doing the job for admin
6682[log] Doing the job for anonymous is requested.
6783[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
6888""" # noqa
0 commit comments