适配器模式

来源:互联网 发布:spss mac 编辑:程序博客网 时间:2024/06/05 14:48
1 <?php 2 //适配器模式-通过适配器去执行第三方方法 3  4 //定义目标接口 5 interface Target{ 6     public function simpleMethod1(); 7     public function simpleMethod2(); 8 } 9 10 class Adatee{11     public function simpleMethod1(){12         echo 'Adatee simpleMethod1<br/>';13     }14 }15 16 //类适配器模式17 class Adapter implements Target{18     private $adatee;19     public function __construct(Adatee $adatee){20         $this->adatee = $adatee;21     }22     public function simpleMethod1(){23         echo $this->adatee->simpleMethod1();24     }25     public function simpleMethod2(){26         echo $this->adatee->simpleMethod12();        27     }28 }29 30 //客户端接口31 class Client{32     public static function main(){33         $adapter = new Adapter(new Adatee());34         $adapter->simpleMethod1();35         36     }37 }38 Client::main();
0 0
原创粉丝点击