什么叫装饰模式? 动态地给一个对象添加一些额外的职责 对人的装饰 <?php class Person { protected $name; function __construct($name='') { $this->name = $name; } public function show() { echo "装扮的".$this->name; } } class Decorator extends Person { protected $component; public function Decorate(Person $component) { $this->component = $component; } public function show() { if($this->component != null) { $this->component->show(); } } } class Tshirts extends Decorator { public function show() { echo "大T恤 "; parent::show(); } } class BigTrouser extends Decorator { public function show() { echo "垮裤 "; parent::show(); } } $person = new Person('我'); $tshirt = new Tshirts(); $bigtrouser = new BigTrouser(); $tshirt->Decorate($person); $bigtrouser->Decorate($tshirt); $bigtrouser->show(); 结果 垮裤 大T恤 装扮的我