[php]php设计模式 Proxy (代理模式)
1 <?php
2 /**
3 * 代理模式
4 *
5 * 为其他对象提供一个代理以控制这个对象的访问
6 *
7 */
8 interface Proxy
9 {
10 publicfunction request();
11 publicfunction display();
12 }
13
14 class RealSubject
15 {
16 publicfunction request()
17 {
18 echo"RealSubject request<br/>";
19 }
20
21 publicfunction display()
22 {
23 echo"RealSubject display<br/>";
24 }
25 }
26
27 class ProxySubject
28 {
29 private$_subject=null;
30 publicfunction __construct()
31 {
32 $this->_subject =new RealSubject();
33 }
34
35 publicfunction request()
36 {
37 $this->_subject->request();
38 }
39
40 publicfunction display()
41 {
42 $this->_subject->display();
43 }
44 }
45
46 $objProxy=new ProxySubject();
47 $objProxy->request();
48 $objProxy->display();
2 /**
3 * 代理模式
4 *
5 * 为其他对象提供一个代理以控制这个对象的访问
6 *
7 */
8 interface Proxy
9 {
10 publicfunction request();
11 publicfunction display();
12 }
13
14 class RealSubject
15 {
16 publicfunction request()
17 {
18 echo"RealSubject request<br/>";
19 }
20
21 publicfunction display()
22 {
23 echo"RealSubject display<br/>";
24 }
25 }
26
27 class ProxySubject
28 {
29 private$_subject=null;
30 publicfunction __construct()
31 {
32 $this->_subject =new RealSubject();
33 }
34
35 publicfunction request()
36 {
37 $this->_subject->request();
38 }
39
40 publicfunction display()
41 {
42 $this->_subject->display();
43 }
44 }
45
46 $objProxy=new ProxySubject();
47 $objProxy->request();
48 $objProxy->display();
think in coding