手机
当前位置:查字典教程网 >编程开发 >php教程 >php设计模式 Delegation(委托模式)
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();

?>

【php设计模式 Delegation(委托模式)】相关文章:

PHP设计模式之装饰者模式代码实例

php计算到指定日期还有多少天的方法

PHP的一个完整SMTP类(解决邮件服务器需要验证时的问题)

php获取json数据所有的节点路径

使用无限生命期Session的方法

php支持中文字符串分割的函数

社区(php&&mysql)四

PHP设计模式之适配器模式代码实例

PHP中的事务使用实例

用PHP 4.2书写安全的脚本

精品推荐
分类导航