PHP實現(xiàn)的簡單適配器模式示例
更新時間:2017年06月22日 10:02:52 作者:北京流浪兒
這篇文章主要介紹了PHP實現(xiàn)的簡單適配器模式,結合具體實例形式分析了php適配器模式的實現(xiàn)技巧與調用方法,需要的朋友可以參考下
本文實例講述了PHP實現(xiàn)的簡單適配器模式。分享給大家供大家參考,具體如下:
<?php //適配器模式-通過適配器去執(zhí)行第三方方法 //定義目標接口 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();
更多關于PHP相關內容感興趣的讀者可查看本站專題:《php面向對象程序設計入門教程》、《PHP基本語法入門教程》、《PHP網(wǎng)絡編程技巧總結》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設計有所幫助。
相關文章
詳解WordPress中添加和執(zhí)行動作的函數(shù)使用方法
這篇文章主要介紹了WordPress中添加和執(zhí)行動作的函數(shù)使用方法,分別講解了add_action()與do_action()的用法,需要的朋友可以參考下2015-12-12php中magic_quotes_gpc對unserialize的影響分析
這篇文章主要介紹了php中magic_quotes_gpc對unserialize的影響,以實例的形式分析了magic_quotes_gpc安全過濾對unserialize造成的影響以及對此的解決方法,非常具有實用價值,需要的朋友可以參考下2014-12-12