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

适配器模式的另一种解释

时间:2015-11-24 16:10:18      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

<?php

//目标角色
interface Target 
{
    public function simpleMethod1();
    public function simpleMethod2();
}

//源角色
class Adaptee 
{
    public function simpleMethod1()
    {
        echo ‘Adapter simpleMethod1‘."<br>";
    }
}

//类适配器角色
class Adapter implements Target 
{
    private $adaptee;
    function __construct(Adaptee $adaptee) 
    {
        $this->adaptee = $adaptee;
    }
    //委派调用Adaptee的sampleMethod1方法
    public function simpleMethod1()
    {
        echo $this->adaptee->simpleMethod1();
    }
    public function simpleMethod2()
    {
        echo ‘Adapter simpleMethod2‘."<br>";
    }
}

//客户端
class Client {

    public static function main() {
        $adaptee = new Adaptee();
        $adapter = new Adapter($adaptee);
        $adapter->simpleMethod1();
        $adapter->simpleMethod2();
    }
}

Client::main();
?>

 

适配器模式的另一种解释

标签:

原文地址:http://www.cnblogs.com/jiufen/p/4991849.html

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