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();
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php面向?qū)ο蟪绦蛟O(shè)計入門教程》、《PHP基本語法入門教程》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP數(shù)組(Array)操作技巧大全》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家PHP程序設(shè)計有所幫助。
相關(guān)文章
詳解WordPress中添加和執(zhí)行動作的函數(shù)使用方法
這篇文章主要介紹了WordPress中添加和執(zhí)行動作的函數(shù)使用方法,分別講解了add_action()與do_action()的用法,需要的朋友可以參考下2015-12-12功能強大的PHP圖片處理類(水印、透明度、旋轉(zhuǎn))
這篇文章主要匯總介紹了php圖片處理類(水印、透明度、縮放、銳化),非常的簡單實用,有需要的小伙伴可以參考下2015-10-10php中magic_quotes_gpc對unserialize的影響分析
這篇文章主要介紹了php中magic_quotes_gpc對unserialize的影響,以實例的形式分析了magic_quotes_gpc安全過濾對unserialize造成的影響以及對此的解決方法,非常具有實用價值,需要的朋友可以參考下2014-12-12