加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php设计模式 Delegation(委托模式)

发布时间:2020-05-28 20:44:36 所属栏目:PHP 来源:互联网
导读:php设计模式 Delegation 委托模式示例代码,需要的朋友可以参考下。

<div class="codetitle"><a style="CURSOR: pointer" data="50436" class="copybut" id="copybut50436" onclick="doCopy('code50436')"> 代码如下:<div class="codebody" id="code50436">
<?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();
?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读