码迷,mamicode.com
首页 > 其他好文 > 详细

适配器模式

时间:2015-04-14 16:30:14      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

适配器模式

<?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();

 

适配器模式

标签:

原文地址:http://www.cnblogs.com/ikasa007/p/4425004.html

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