来一段关于设计模式的代码

<?php
/**
 * PHP设计模式之代理模式
 * 下面的代码通俗易懂。反应了现实社会中的一些情况
 * @author www.PHPdesigner.org 
 * @copyright 转载请注明来源...
 *
 */
interface GiveGift{
    public function 
giveMoney();
    public function 
giveCar();
    public function 
giveGirl();
}
/**
 * 普通人送礼
 *
 */
class OrdinaryPeople implements GiveGift{
    protected  
$name;
    public function 
__construct(Leader $name){
        
$this->name $name->name;
    }
    public function 
giveMoney(){
        echo 
送你钱.$this->name;
    }
    public function 
giveCar(){
        echo 
送你车.$this->name;
    }
    public function 
giveGirl(){
        echo 
送你女人.$this->name;
    }
}
/**
 * 代理人
 *
 */
class ProxyPerson implements GiveGift {
    public 
$give;
    public function 
__construct($name){
        
$this->give = new OrdinaryPeople($name);
    }
    public function 
giveMoney(){
        
$this->give->giveMoney();
    }
    public function 
giveCar(){
        
$this->give->giveGirl();
    }
    public function 
giveGirl(){
        
$this->give->giveGirl();
    }
}
/**
 * xx领导
 *
 */
class Leader{
    public 
$name;
    
//Other function ....
}
$gift = new Leader();
$gift->name xx官员;

$proxy = new ProxyPerson($gift);
$proxy->giveCar();
$proxy->giveGirl();
$proxy->giveMoney();      

关于PHP博客

PHP blogger

博客-致力于分享PHP技术的开发心得, 记录站长生活的点点滴滴,PHP博客采用PHP 面向对象编程+Smarty模板引擎+Mysql数据库 开发(全站纯静态化与伪静态化)
QQ:334192009
电邮:admin@PHPdesigner.org

本站搜索

本站最新文章

博客最近档案

友情链接