The content of this article is about the singleton mode of PHP design pattern, which has certain reference value. Now I share it with you. Friends in need can refer to it
Single case mode ( Singleton) is also one of the creative modes, and it is not difficult to understand.
After reading some information, the most basic application is the task manager.
In fact, my personal understanding is that cannot create a second identical object.
The program will internally determine whether the object has been created. If not, create it. If it already exists, use it directly.
Made some simple records, as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
##The output result is:
The hero created by single1 is: Zhuge Liang
The hero created by single1 is: Zhou Yu
The hero created by single2 is: Zhou Yu
Abstract Factory of PHP Design Pattern
Factory Method of PHP Design Pattern
PHP Design Pattern Simple Factory
The above is the detailed content of PHP design pattern singleton pattern. For more information, please follow other related articles on the PHP Chinese website!