【编者按】:网学网PHP为您提供php设计模式 Delegation(委托模式)参考,解决您在php设计模式 Delegation(委托模式)学习中工作中的难题,参考学习。
复制代码 代码如下:
<?php
/**
* 委托模式 示例
*
* @create_date: 2010-01-04
*/
class PlayList
{
var
php设计模式 Delegation(委托模式)_网学
浏览:
songs = array();
var
php设计模式 Delegation(委托模式)_网学
浏览:
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 rm
vbPlayListDelegation
{
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();
?>