Original link: [design mode] multi-case mode and single-case mode difference
Both the multi-case mode and the singleton mode prohibit the external instantiation directly, and provide the external instance of the loop using the static factory method. The difference is that there is only one instance of the singleton pattern, while multiple instances can have multiple cases.
Multiple cases often have a clustered property that is used to iterate through instances of the created instance by registering them with the aggregation attribute. In general, a typical multiple class has an internal state that can be used to differentiate between instances, and only one instance exists for each internal state.
Original link: Advantages and disadvantages of singleton mode
Key Benefits:
1. Provides controlled access to the unique instance.
2, because there is only one object in the system memory, so it can save system resources, for some of the objects need to be created and destroyed frequently the singleton pattern can undoubtedly improve the performance of the system.
3. Allow a variable number of instances.
Main disadvantages:
1, because there is no abstraction layer in the simple interest mode, the expansion of the Singleton class has great difficulty.
2, the single-case category of excessive responsibility, to a certain extent, contrary to the "single principle of responsibility."
3, abuse of a single case will bring some negative problems, such as to save resources to the database connection pool object design as a singleton class, may cause the sharing connection pool object too many programs and a connection pool overflow, if the instantiated object is not exploited for a long time, the system will be considered as garbage, which will result in the loss of object state.
The difference between a singleton pattern and a multi-instance pattern (RPM)