适配器模式

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();
原文地址:https://www.cnblogs.com/yulei126/p/6786095.html