php設(shè)計(jì)模式 Delegation(委托模式)
更新時(shí)間:2011年06月26日 11:21:00 作者:
php設(shè)計(jì)模式 Delegation 委托模式示例代碼,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:
<?php
/**
* 委托模式 示例
*
* @create_date: 2010-01-04
*/
class PlayList
{
var $_songs = array();
var $_object = null;
function PlayList($type)
{
$object = $type."PlayListDelegation";
$this->_object = new $object();
}
function addSong($location,$title)
{
$this->_songs[] = array("location"=>$location,"title"=>$title);
}
function getPlayList()
{
return $this->_object->getPlayList($this->_songs);
}
}
class mp3PlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "mp3")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
class rmvbPlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);
if(strtolower($item['extension']) == "rmvb")
{
$aResult[] = $item;
}
}
return $aResult;
}
}
$oMP3PlayList = new PlayList("mp3");
$oMP3PlayList->getPlayList();
$oRMVBPlayList = new PlayList("rmvb");
$oRMVBPlayList->getPlayList();
?>
相關(guān)文章
php實(shí)現(xiàn)的支持imagemagick及gd庫(kù)兩種處理的縮略圖生成類
這篇文章主要介紹了php實(shí)現(xiàn)的支持imagemagick及gd庫(kù)兩種處理的縮略圖生成類,包含了用法的詳細(xì)描述,非常實(shí)用,需要的朋友可以參考下2014-09-09PHP實(shí)現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法【附demo源碼】
這篇文章主要介紹了PHP實(shí)現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法,涉及php基于curl的遠(yuǎn)程數(shù)據(jù)操作相關(guān)技巧,需要的朋友可以參考下2016-10-10PHP操作MongoDB時(shí)的整數(shù)問題及對(duì)策說明
本文所說的整數(shù)問題,其實(shí)并不是MongoDB的問題,而是PHP驅(qū)動(dòng)的問題2011-05-05php專用數(shù)組排序類ArraySortUtil用法實(shí)例
這篇文章主要介紹了php專用數(shù)組排序類ArraySortUtil用法,實(shí)例分析了ArraySortUtil實(shí)現(xiàn)數(shù)組排序的方法與對(duì)應(yīng)使用技巧,需要的朋友可以參考下2015-04-04golang 調(diào)用 php7詳解及實(shí)例
這篇文章主要介紹了golang 調(diào)用 php7詳解及實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-01-01php字符串函數(shù)學(xué)習(xí)之strstr()
這篇文章主要介紹了php字符串函數(shù)學(xué)習(xí)之strstr(),本文講解了它的定義和用法、參數(shù)描述、提示和注釋以及多個(gè)使用示例,需要的朋友可以參考下2015-03-03