PHP面试题之设计模式

Linux大全评论818 views阅读模式

设计模式是技术面试的时候难免会被问到的一个问题,特别会让你举例说明各种设计模式的使用场景。

使用设计模式可以减轻我们的工作量,优化我们的代码。

/**
 * 单例模式
 * 
 */
class Config
{
    static private $_instance = NULL;
    private $_settings = array();
    private function __construct(){}
    private function __clone(){};

    static function getInstance()
    {
        if(self::$_intance == NULL){
            self::$_intance = new Config();
        }
        return self:$_intance;
    }

    public function set($index,$value)
    {
        $this->_setting[$index] = $value;
    }

    public function get($index)
    {
        return $this->_settings[$index];
    }
}

企鹅博客
  • 本文由 发表于 2020年2月4日 21:32:48
  • 转载请务必保留本文链接:https://www.qieseo.com/182419.html

发表评论