首页 >php教程 >php手册 >php设计模式 Proxy (代理模式)

php设计模式 Proxy (代理模式)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-21 08:54:211263浏览

复制代码 代码如下:


/**
* 代理模式
*
* 为其他对象提供一个代理以控制这个对象的访问
*
*/
interface Proxy
{
public function request();
public function display();
}

class RealSubject
{
public function request()
{
echo "RealSubject request
";
}

public function display()
{
echo "RealSubject display
";
}
}

class ProxySubject
{
private $_subject = null;
public function __construct()
{
$this->_subject = new RealSubject();
}

public function request()
{
$this->_subject->request();
}

public function display()
{
$this->_subject->display();
}
}

$objProxy = new ProxySubject();
$objProxy->request();
$objProxy->display();



声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn