作者:kongxujimo | 来源:互联网 | 2017-05-13 02:37
PHP面试题之设计模式,php试题设计模式。PHP面试题之设计模式,php试题设计模式设计模式是技术面试的时候难免会被问到的一个问题,特别会让你举例说明各种设计模式的使用场景
PHP面试题之设计模式,php试题设计模式
设计模式是技术面试的时候难免会被问到的一个问题,特别会让你举例说明各种设计模式的使用场景。
使用设计模式可以减轻我们的工作量,优化我们的代码。
设计模式非常的多,这里介绍单例模式,工厂模式,组合模式,策略模式4种模式
/**
* 单例模式
*
*/
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];
}
}
http://www.bkjia.com/PHPjc/1059919.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1059919.htmlTechArticlePHP面试题之设计模式,php试题设计模式 设计模式是技术面试的时候难免会被问到的一个问题,特别会让你举例说明各种设计模式的使用场景...