手机
当前位置:查字典教程网 >编程开发 >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 ajax 异步执行不等待执行结果的处理方法

PHP浮点数精度问题汇总

PHP处理密码的几种方式

用PHP 4.2书写安全的脚本

第十二节 类的自动加载 [12]

社区(php&&mysql)四

WIN98下Apache1.3.14+PHP4.0.4的安装

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

使用无限生命期Session的方法

精品推荐
分类导航