File tree Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Expand file tree Collapse file tree 2 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Design pattern "Proxy" (Structural)
5
+ * This is demo code
6
+ * See for details: http://maxsite.org/page/php-patterns
7
+ */
8
+
9
+ /**
10
+ * Real Class
11
+ */
12
+ class RealClass
13
+ {
14
+ public function operation1 ()
15
+ {
16
+ echo 'RealClass operation 1 <br> ' ;
17
+ }
18
+
19
+ public function operation2 ()
20
+ {
21
+ echo 'RealClass operation 2 <br> ' ;
22
+ }
23
+ }
24
+
25
+ /**
26
+ * Proxy for Real Class
27
+ */
28
+ class ProxyClass
29
+ {
30
+ protected $ class ;
31
+
32
+ public function __construct ()
33
+ {
34
+ $ this ->class = new RealClass ();
35
+ }
36
+
37
+ /**
38
+ * execute RealClass operation1
39
+ */
40
+ public function run1 ()
41
+ {
42
+ $ this ->class ->operation1 ();
43
+ }
44
+
45
+ /**
46
+ * execute RealClass operation2
47
+ */
48
+ public function run2 ()
49
+ {
50
+ $ this ->class ->operation2 ();
51
+ }
52
+ }
53
+
54
+
55
+ /**
56
+ * demo
57
+ */
58
+
59
+ /**
60
+ * create Decorator for Real Class
61
+ */
62
+ $ p = new ProxyClass ();
63
+
64
+ $ p ->run1 ();
65
+ $ p ->run2 ();
66
+ /*
67
+ RealClass operation 1
68
+ RealClass operation 2
69
+ */
70
+
71
+
72
+ # end of file
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ See details on http://maxsite.org/page/php-patterns
18
18
* "Bridge" (Structural)
19
19
* "Decorator" (Structural)
20
20
* "Flyweight" (Structural)
21
+ * "Proxy" (Structural)
21
22
22
23
23
24
(c) MaxSite.org, 2019, http://maxsite.org/
You can’t perform that action at this time.
0 commit comments