首页 > php教程 > php手册 > 适配器模式,适配器模式java

适配器模式,适配器模式java

WBOY
发布: 2016-06-13 09:07:14
原创
1594 人浏览过

适配器模式,适配器模式java

适配器模式

<?<span>php
</span><span>//</span><span>适配器模式-通过适配器去执行第三方方法

//定义目标接口</span>
<span>interface</span><span> Target{
    </span><span>public</span> <span>function</span><span> simpleMethod1();
    </span><span>public</span> <span>function</span><span> simpleMethod2();
}

</span><span>class</span><span> Adatee{
    </span><span>public</span> <span>function</span><span> simpleMethod1(){
        </span><span>echo</span> 'Adatee simpleMethod1<br/>'<span>;
    }
}

</span><span>//</span><span>类适配器模式</span>
<span>class</span> Adapter <span>implements</span><span> Target{
    </span><span>private</span> <span>$adatee</span><span>;
    </span><span>public</span> <span>function</span> __construct(Adatee <span>$adatee</span><span>){
        </span><span>$this</span>->adatee = <span>$adatee</span><span>;
    }
    </span><span>public</span> <span>function</span><span> simpleMethod1(){
        </span><span>echo</span> <span>$this</span>->adatee-><span>simpleMethod1();
    }
    </span><span>public</span> <span>function</span><span> simpleMethod2(){
        </span><span>echo</span> <span>$this</span>->adatee-><span>simpleMethod12();        
    }
}

</span><span>//</span><span>客户端接口</span>
<span>class</span><span> Client{
    </span><span>public</span> <span>static</span> <span>function</span><span> main(){
        </span><span>$adapter</span> = <span>new</span> Adapter(<span>new</span><span> Adatee());
        </span><span>$adapter</span>-><span>simpleMethod1();
        
    }
}
Client</span>::main();
登录后复制

 

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板