首页 > 学院 > 开发设计 > 正文

适配器模式

2019-11-15 02:09:58
字体:
来源:转载
供稿:网友
适配器模式

适配器模式

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


上一篇:观察者模式

下一篇:装饰器模式

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表