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();
?>
相關(guān)文章
php實現(xiàn)的支持imagemagick及gd庫兩種處理的縮略圖生成類
這篇文章主要介紹了php實現(xiàn)的支持imagemagick及gd庫兩種處理的縮略圖生成類,包含了用法的詳細描述,非常實用,需要的朋友可以參考下2014-09-09PHP實現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法【附demo源碼】
這篇文章主要介紹了PHP實現(xiàn)登錄搜狐廣告獲取廣告聯(lián)盟數(shù)據(jù)的方法,涉及php基于curl的遠程數(shù)據(jù)操作相關(guān)技巧,需要的朋友可以參考下2016-10-10php專用數(shù)組排序類ArraySortUtil用法實例
這篇文章主要介紹了php專用數(shù)組排序類ArraySortUtil用法,實例分析了ArraySortUtil實現(xiàn)數(shù)組排序的方法與對應使用技巧,需要的朋友可以參考下2015-04-04