首页 > 其他 > 详细

适配器模式

时间:2017-04-29 20:38:52      阅读:232      评论:0      收藏:0      [点我收藏+]
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();

适配器模式

原文:http://www.cnblogs.com/yulei126/p/6786095.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!