Application of Service locator location and singleton mode in PHP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.