您的位置:首页 > 编程语言 > PHP开发

php设计模式 Delegation(委托模式)

2011-06-26 00:00 2336 查看
<?php 
/** 
* 委托模式 示例 
* 
* @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(); 
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息