Php design mode: single-case and multi-case design mode. Singleton mode and the uncommon Multiton mode control the number of classes in an application. For example, the mode name can only be instantiated once, with only one object. The Singleton mode and the uncommon Multiton mode control the number of classes in the application. For example, the mode name can only be instantiated once for a single instance and only one object. the mode can be instantiated multiple times.
Based on the Singleton feature, we often use Singleton to configure the application and define variables that may be accessed at any time in the application. But sometimes Singleton is not recommended because it generates a global state and
This single root object does not encapsulate any system functions. In most cases, unit testing and debugging are difficult. The reader decides based on the actual situation.
Sample code:
Multiton is similar to singleton. The difference is that the latter requires the getInstance () function to pass key values.
For a given key value, only a unique object instance exists. if multiple nodes exist, each node has a unique table identifier, in addition, each node may appear multiple times in a single execution (such as a node in cms), so you can use the Multiton mode to implement these nodes. the Multiton mode saves memory, make sure that multiple instances of the same object do not conflict.
Example:
References: php and mysql expert programming
The Singleton mode and the uncommon Multiton mode control the number of classes in the application. For example, the mode name can only be instantiated once. there is only one object. the mode of multiple instances can be...