Home >Backend Development >PHP Tutorial >PHP interview question design pattern, PHP test question design pattern_PHP tutorial

PHP interview question design pattern, PHP test question design pattern_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-12 09:07:341357browse

Design pattern of PHP interview questions, PHP test question design pattern

Design pattern is a question that will inevitably be asked during technical interviews. In particular, it will ask you to give examples of various Design pattern usage scenarios.

Using design patterns can reduce our workload and optimize our code.

There are many design patterns. Here we introduce 4 patterns: singleton pattern, factory pattern, combination pattern and strategy pattern

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

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

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

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1059919.htmlTechArticlePHP interview questions design patterns, PHP test questions design patterns design patterns are inevitably asked during technical interviews A question in particular will ask you to give examples of usage scenarios of various design patterns...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn