CopyCode The Code is as follows: <? PHP
/**
* Delegation 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" => $ 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 ();
?>