Singleton mode instantiates an object and puts it in a static variable for the program to call.
Service positioning (Servicelocator) is the object workshop factory, the caller object directly calls the service Locator, and the called object to mitigate the dependency, so if the call object replacement, directly modify the Servicelocator registration can be, There is no need to modify the calls in many places in the program, thereby mitigating dependencies.
I am learning singleton mode of thinking, there is a question always around myself, the singleton mode is static variable Bai, why to call a singleton mode, what are the benefits? Static class + static method not very good?
When I studied servicelocator the latter understood that the singleton pattern is an object placed in a static variable, which reduces the degree of coupling of the program, because the object is easily replaced by another object, and static classes are called directly.
Servicelocator How to implement it, the following code examples.
Implement Servicelocator Yourself
Servicelocator in the YII2 framework
Summarize
Application of Service locator location and singleton mode in PHP