|
A design pattern is a technical interview question will inevitably be asked, in particular, will let you design patterns illustrate various usage scenarios.
Use of design patterns can reduce our workload, optimize our code.
Design patterns very much, here singleton, factory mode, combined mode, the policy mode 4 modes
/ **
*
* /
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];
}
} |
|
|
|