首页 > 其他 > 详细

适配器模式的另一种解释

时间:2015-11-24 16:07:06      阅读:280      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!