码迷,mamicode.com
首页 > Web开发 > 详细

适配器模式 - 设计模式 - PHP版

时间:2017-10-26 15:32:40      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:color   oam   适配   simple   http   blog   targe   ati   调用   

 1 <?php
 2 /*
 3  * 适配器模式
 4  * 
 5  * 参考:http://www.cnblogs.com/whoamme/p/3324325.html
 6  * 
 7  */
 8 //目标角色  
 9 interface Target {
10     public function simpleMethod1();
11     public function simpleMethod2();
12 }
13 //源角色  
14 class Adaptee {
15     public function myMethod() {
16         echo ‘Adapter myMethod‘ . "<br>";
17     }
18 }
19 //类适配器角色  
20 class Adapter implements Target {
21     private $adaptee;
22     function __construct(Adaptee $adaptee) {
23         $this->adaptee = $adaptee;
24     }
25     //委派调用Adaptee的myMethod方法  
26     public function simpleMethod1() {
27         echo $this->adaptee->myMethod();
28     }
29     public function simpleMethod2() {
30         echo ‘Adapter simpleMethod2‘ . "<br>";
31     }
32 }
33 //客户端  
34 class Client {
35     public static function main() {
36         $adaptee = new Adaptee();
37         $adapter = new Adapter($adaptee);
38         $adapter->simpleMethod1();
39         $adapter->simpleMethod2();
40     }
41 }
42 Client::main();

 

适配器模式 - 设计模式 - PHP版

标签:color   oam   适配   simple   http   blog   targe   ati   调用   

原文地址:http://www.cnblogs.com/benben7466/p/7736525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!