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

 2025-01-15  阅读 256  评论 8  点赞 385

摘要:复制代码 代码如下:
复制代码 代码如下:

<?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();
?>


标签:phpphp教程

评论列表:

显示更多评论

发表评论:

管理员

承接各种程序开发,外贸网站代运营,外贸网站建设等项目
  • 内容2460
  • 积分67666
  • 金币86666

Copyright © 2024 LS'Blog-保定PHP程序员老宋个人博客 Inc. 保留所有权利。 Powered by LS'blog 3.0.3

页面耗时0.0285秒, 内存占用1.93 MB, 访问数据库27次

冀ICP备19034377号