适配器模式,适配器模式java_PHP教程

WBOY
發布: 2016-07-13 09:57:22
原創
823 人瀏覽過

适配器模式,适配器模式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();
登入後複製

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/983245.htmlTechArticle适配器模式,适配器模式java 适配器模式 ? php // 适配器模式-通过适配器去执行第三方方法//定义目标接口 interface Target{ public function simpleM...
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板