zoukankan      html  css  js  c++  java
  • [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();
    ?>
    
  • 相关阅读:
    Bzoj4627 [BeiJing2016]回转寿司
    Bzoj1901 Zju2112 Dynamic Rankings
    COGS728. [网络流24题] 最小路径覆盖问题
    Bzoj4568 [Scoi2016]幸运数字
    Bzoj2728 [HNOI2012]与非
    HDU4609 3-idiots
    Bzoj2194 快速傅立叶之二
    Bzoj2179 FFT快速傅立叶
    模拟52 题解
    模拟51 题解
  • 原文地址:https://www.cnblogs.com/bluefrog/p/1925926.html
Copyright © 2011-2022 走看看