head first 設計模式 php設計模式 Delegation委託模式

WBOY
發布: 2016-07-29 08:45:47
原創
1006 人瀏覽過

複製程式碼程式碼如下:


/**
* 委託模式 範例
*
* @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"=>$標題);
}
function getPlayList()
{
return $this->_object->getPlayList($this->_songs);
}
} class mp3PlayDeleg🎜>}
} class mp3PlayDelegy> >{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$item)
{
$path = pathinfo($item['location']);if(strtolower($item['extension']) == "mp3")
{
$aResult[] = $item
}
}
回傳$aResult;
}
}
class rmvbPlayListDelegation
{
function getPlayList($songs)
{
$aResult = arrayat($songs); >foreach($songs as $key=>$item)
{
$path = pathinfo($item['location'])
if(strtolower($item['extension]); '] ) == "rmvb")
{
$aResult[] =
}
}
回傳$aResult
}
}
$oMP3PlayListList = new PlayList( "mp3");
$oRMVBPlayList = new PlayList("rmvb");
$oRMVBPlayList->getPlayList(); ? >


以上就介紹了headfirst設計模式php設計模式委託委託模式,包括headfirst設計模式的內容,希望對PHP教學有興趣的朋友有幫助。

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!