Home >Backend Development >PHP Tutorial >PHP design pattern, singleton pattern, singleton pattern and multi-case pattern, java singleton design pattern, flyweight pattern, singleton pattern
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?
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.
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.