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程序設計有所幫助。
相關文章
PHP實現(xiàn)獲取MySQL數(shù)據(jù)庫的記錄數(shù)據(jù)
如果后臺數(shù)據(jù)處理使用PHP來進行,那么就要有相應的數(shù)據(jù)處理及返回。最常用的就是獲取記錄總數(shù)和表記錄查詢結果。本文將為大家介紹如何利用PHP實現(xiàn)獲取MySQL數(shù)據(jù)庫的記錄數(shù)據(jù),需要的可以參考一下2022-02-02
PHP使用Mysqli類庫實現(xiàn)完美分頁效果的方法
這篇文章主要介紹了PHP使用Mysqli類庫實現(xiàn)完美分頁效果的方法,結合實例形式分析了PHP使用Mysqli類庫的相關配置文件設置,數(shù)據(jù)庫操作及分頁的相關實現(xiàn)技巧,需要的朋友可以參考下2016-04-04

