Home > Backend Development > PHP Tutorial > 1 PHP design pattern---factory pattern

1 PHP design pattern---factory pattern

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:02:40
Original
885 people have browsed it

Basic design patterns
1 PHP 设计模式---工厂模式


1. Factory pattern

<code><span>//如果很多页面都 new 一个Database 对象,那么一旦Database作出改动,则需要在多个</span><span>//页面进行相应的改动。而用工厂模式,只需要改动一个地方。</span><span><?php</span><span>namespace</span><span>IMooc</span>;

<span><span>class</span><span>Factory</span>
{</span><span>static</span><span><span>function</span><span>createDatabase</span><span>()</span>
    {</span><span>$db</span> = <span>new</span> Database();
        <span>return</span><span>$db</span>;
    }
}</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced 1 PHP design pattern---factory pattern, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template