name = $name; } public function eat(){ echo $this->name."吃钣"; }}class Mother implements Person{ private $baby; public function __construct($baby){ $this->baby = $baby; } private function eatBefor(){ echo "吃之前"; } private function eatAfter(){ echo "吃之后"; } public function eat(){ $this->eatBefor(); $this->baby->eat(); $this->eatAfter(); }}//适配器模式interface TypeA{ public function insert();}interface TypeB{ public function connect();}class TypeAimpl implements TypeA{ public function insert(){ echo "Start insert"; }}class TypeBimpl implements TypeB{ public function connect(){ echo "Start connect"; }}class createA{ private $typeA; public function __construct($typeA){ $this->typeA = $typeA; } public function dotypeA(){ echo "other...things"; $this->typeA->insert(); }}class Adapter implements TypeA{ private $typeB; public function __construct($typeB){ $this->typeB = $typeB; } public function insert(){ $this->typeB->connect(); }}$typeAimpl = new TypeAimpl();$typeBimpl = new TypeBimpl();$Adapter = new Adapter($typeBimpl);$createA = new createA($typeAimpl);$createB = new createA($Adapter);$createA->dotypeA();$createB->dotypeA();