File tree 1 file changed +48
-0
lines changed
1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #
2
+ # Python Design Patterns: Proxy
3
+ # Author: Jakub Vojvoda [github.com/JakubVojvoda]
4
+ # 2016
5
+ #
6
+ # Source code is licensed under MIT License
7
+ # (for more details see LICENSE)
8
+ #
9
+
10
+ import sys
11
+
12
+ #
13
+ # Subject
14
+ # defines the common interface for RealSubject and Proxy
15
+ # so that a Proxy can be used anywhere a RealSubject is expected
16
+ #
17
+ class Subject :
18
+ def request (self ):
19
+ pass
20
+
21
+ #
22
+ # Real Subject
23
+ # defines the real object that the proxy represents
24
+ #
25
+ class RealSubject (Subject ):
26
+ def __init__ (self ):
27
+ Subject .__init__ (self )
28
+
29
+ def request (self ):
30
+ print ("Real Subject request." )
31
+
32
+ #
33
+ # Proxy
34
+ # maintains a reference that lets the proxy access the real subject
35
+ #
36
+ class Proxy (Subject ):
37
+ def __init__ (self ):
38
+ Subject .__init__ (self )
39
+ self ._subject = RealSubject ()
40
+
41
+ def request (self ):
42
+ self ._subject .request ()
43
+
44
+
45
+ if __name__ == "__main__" :
46
+ proxy = Proxy ()
47
+ proxy .request ()
48
+
You can’t perform that action at this time.
0 commit comments