Skip to content

Commit 8dbfbd6

Browse files
committed
add changes to example to contain client real-subject usage
1 parent 7e6254c commit 8dbfbd6

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

append_output.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ output_marker='OUTPUT = """'
1010
# get everything (excluding part between `output_marker` and the end of the file)
1111
# into `src` var
1212
src=$(sed -n -e "/$output_marker/,\$!p" "$1")
13-
output=$(python "$1")
13+
output=$(python3 "$1")
1414

1515
echo "$src" > $1
1616
echo -e "\n" >> $1

patterns/structural/proxy.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5763
if __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

6378
OUTPUT = """
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

Comments
 (0)