什么叫代理模式 为其它对象提供一种代理以控制对这人对象的访问 为别人做嫁衣--送礼物给女孩 <?php /** * 送礼物接口 */ interface IGiveGift { function give_dolls(); function give_flowers(); function give_chocolate(); } /** * 追求者 */ class Pursuit implements IGiveGift { public $name; public function __construct($name) { $this->name = $name; } public function give_dolls() { return $this->name.",送给你洋娃娃"; } public function give_flowers() { return $this->name.",送给你玫瑰花"; } public function give_chocolate() { return $this->name.",送给你巧克力"; } } /** * 代理 */ class Proxy { public $pursuit; public function __construct(Pursuit $pursuit) { $this->pursuit = $pursuit; } public function give_dolls() { return $this->pursuit->give_dolls(); } public function give_flowers() { return $this->pursuit->give_flowers(); } public function give_chocolate() { return $this->pursuit->give_chocolate(); } } $pursuit = new Pursuit('娇娇'); $proxy = new Proxy($pursuit); echo $proxy->give_dolls(); echo "/n"; echo $proxy->give_flowers(); echo "/n"; echo $proxy->give_chocolate(); 结果 娇娇,送给你洋娃娃娇娇,送给你玫瑰花娇娇,送给你巧克力