適配器模式
<?php //適配器模式-通過適配器去執行第三方方法 //定義目標接口 interface Target{ public function simpleMethod1(); public function simpleMethod2(); } class Adatee{ public function simpleMethod1(){ echo 'Adatee simpleMethod1<br/>'; } } //類適配器模式 class Adapter implements Target{ private $adatee; public function __construct(Adatee $adatee){ $this->adatee = $adatee; } public function simpleMethod1(){ echo $this->adatee->simpleMethod1(); } public function simpleMethod2(){ echo $this->adatee->simpleMethod12(); } } //客戶端接口 class Client{ public static function main(){ $adapter = new Adapter(new Adatee()); $adapter->simpleMethod1(); } } Client::main();