Home >Backend Development >PHP Tutorial >Detailed explanation and cases of PHP proxy mode

Detailed explanation and cases of PHP proxy mode

墨辰丷
墨辰丷Original
2018-05-16 14:40:002152browse

This article mainly introduces the detailed explanation and cases of PHP proxy mode. Interested friends can refer to it. I hope it will be helpful to everyone.

The code is as follows:

<?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();  
    }  
}

Output structure:

Professional talents do professional things

Related recommendations:

Detailed explanation of the proxy mode of JS design pattern

The proxy mode of Javascript

The proxy mode of PHP design ideas The practice of separation from reading and writing

The above is the detailed content of Detailed explanation and cases of PHP proxy mode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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