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

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

WBOY
Release: 2016-06-21 08:54:21
Original
1258 people have browsed it

复制代码 代码如下:


/**
* 代理模式
*
* 为其他对象提供一个代理以控制这个对象的访问
*
*/
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();



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template