Copy CodeThe code is as follows:
/**
* Delegate Mode Example
*
* @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" and "+ $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;
}
}
$oMP 3PlayList = new PlayList ("MP3");
$oMP 3playlist->getplaylist ();
$oRMVBPlayList = new PlayList ("RMVB");
$oRMVBPlayList->getplaylist ();
?>
The above describes the head first design mode PHP design mode delegation delegate mode, including the head first design mode of the content, I hope to be interested in PHP tutorial friends helpful.