複製程式碼程式碼如下:
/**
* 委託模式 範例
*
* @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教學有興趣的朋友有幫助。