服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - PHP教程 - php设计模式 Delegation(委托模式)

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

2019-12-02 13:50PHP教程网 PHP教程

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

延伸 · 阅读

精彩推荐