PHP面试题之设计模式,php试题设计模式
PHP面试题之设计模式,php试题设计模式
设计模式是技术面试的时候难免会被问到的一个问题,特别会让你举例说明各种设计模式的使用场景。
使用设计模式可以减轻我们的工作量,优化我们的代码。
设计模式非常的多,这里介绍单例模式,工厂模式,组合模式,策略模式4种模式
<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>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
