-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathproxy.py
More file actions
38 lines (30 loc) · 743 Bytes
/
Copy pathproxy.py
File metadata and controls
38 lines (30 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python
# -*- coding : utf-8 -*-
"""
brief:
Proxy.
Provide a surrogate or placeholder for
another object to control access to it.
Subject
| |
RealSubject <- Proxy
"""
class RealSubject(object):
def request(self):
print("RealSubject Request")
class Proxy(object):
def __init__(self):
self._subject = None
def set_subject(self, subject):
self._subject = subject
def request(self):
if self._subject != None:
self._subject.request()
else:
print("No Subject.")
if __name__ == '__main__':
subject = RealSubject()
proxy = Proxy()
proxy.set_subject(subject)
# Use a proxy to do something for the subject.
proxy.request()