Home >Backend Development >PHP Tutorial >PHP design pattern, singleton pattern, singleton pattern and multi-case pattern, java singleton design pattern, flyweight pattern, singleton pattern

PHP design pattern, singleton pattern, singleton pattern and multi-case pattern, java singleton design pattern, flyweight pattern, singleton pattern

WBOY
WBOYOriginal
2016-07-29 08:52:441006browse
What is a singleton and what does it do?

Single case pattern can be understood from the name. Just once. An example is to instantiate an object, which means I instantiate an object no matter how many times I use it. What is the role of this design pattern?

The singleton mode can ensure that a class in the system has only one instance and the instance is easy to access from the outside world, thus facilitating the control of the number of instances and saving system resources.

For example, we want to write a class that operates mysql. Perform the database connection operation in the construction method. If it is the usual way of writing, this class will be new every time. We have created a database connection here. For example, I have 100 files here that all call this type at the same time. Every time you declare this mysql class, you must connect to the database. This cost is still quite high. To solve this problem. The singleton pattern was born.


php 设计模式单例模式,c#单例设计模式,单例模式 多例模式,单例模式 工厂模式,工厂模式和单例模式,单例模式和多例模式,java单例设计模式,享元模式 单例模

The above introduces the PHP design pattern and singleton pattern, including the design pattern and singleton pattern. I hope it will be helpful to friends who are interested in PHP tutorials.

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