ホームページ  >  記事  >  バックエンド開発  >  head first デザイン パターン PHP デザイン パターン 委任 委任パターン

head first デザイン パターン PHP デザイン パターン 委任 委任パターン

WBOY
WBOYオリジナル
2016-07-29 08:45:471009ブラウズ

复制代码代码如下:


/**
* デリゲート モードの例
*
* @create_date: 2010-01-04
*/
class PlayList
{
var $_songs = array();
var $_object = null;
関数 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=>$ite​​m)
{
$path = pathinfo($item['location']);
if(strto lower($item['extension']) == "mp3")
{
$aResult[] = $item;
}
}
$aResult を返します。
}
}
class rmvbPlayListDelegation
{
function getPlayList($songs)
{
$aResult = array();
foreach($songs as $key=>$ite​​m)
{
$path = pathinfo($item['location']);
if(strto lower($item['extension']) == "rmvb")
{
$aResult[] = $item;
}
}
$aResult を返します。
}
}
$oMP3PlayList = 新しい PlayList("mp3");
$oMP3PlayList->getPlayList();
$oRMVBPlayList = 新しいプレイリスト("rmvb");
$oRMVBPlayList->getPlayList();
?>

以上は、ヘッド ファースト デザイン モード php デザイン モード委任モードを介して、ヘッド ファースト デザイン モードの内容が含まれており、PHP 教則に関心のある友人の助けになることが望ましいです。

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。