php设计模式 Delegation(委托模式)
更新时间:2011年06月26日 11:21:00 作者:
php设计模式 Delegation 委托模式示例代码,需要的朋友可以参考下。
复制代码 代码如下:
<?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();
?>
相关文章
thinkphp项目部署到Linux服务器上报错“模板不存在”如何解决
一个项目部署到Linux服务器上去的时候,发现某些模板竟然会报错说“模板不存在:/Application/Admin/....”,这篇文章就是介绍了thinkphp项目部署到Linux服务器上报错“模板不存在”的解决方法,感兴趣的小伙伴们可以参考一下2016-04-04


最新评论