Php design mode (Delegation mode ). Copy the code as follows :? Php *** delegate mode example ** @ create_date: 2010-01-04 * classPlayList {var $ _ songsarray (); var $ _ objectnull; functionPlayList ($ type) {$ o
The code is as follows:
/**
* 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 ();
?>
The http://www.bkjia.com/PHPjc/323788.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323788.htmlTechArticle code is as follows :? Php/*** delegate mode example ** @ create_date: 2010-01-04 */class PlayList {var $ _ songs = array (); var $ _ object = null; function PlayList ($ type) {$ o...