来一段关于设计模式的代码
<?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();