时间:2021-07-01 10:21:17 帮助过:15人阅读
代码如下:
<?php
// 代理模式 index.php
header("Content-Type:text/html;charset=utf-8");
require_once "Proxy.php";
// 代理对象
$obj = new Proxy("专业的事情");
// 展示
$obj->Show();
[php] view plain copy
<?php
// 代理接口
interface IProxy {
function Show();
}
// 真实对象
Class Profession implements IProxy
{
/**
* 私有 专业事情
* @var string
*/
private $Things;
/**
* 构造方法
* @access public
* @param string $things 专业的事情
*/
function __construct($things){
$this->Things = $things;
}
/**
* 真实对象的展示方法
* @access public
*/
function Show(){
echo "专业的人才做{$this->Things}";
}
}
// 代理对象
Class Proxy implements IProxy
{
/**
* 私有真实对象变量
* @var object
*/
private $Pro;
/**
* 构造方法
* @access public
* @param string $things 专业的事情
*/
function __construct($things){
$this->Pro = new Profession($things);
}
/**
* 代理对象的展示方法
* @access public
*/
function Show(){
$this->Pro->Show();
}
}输出结构:
专业的人才做专业的事情
相关推荐:
JS设计模式之代理模式详解
Javascript的代理模式
PHP设计思想之代理模式与读写分离的实践
以上就是PHP代理模式详解及案例的详细内容,更多请关注Gxl网其它相关文章!