On his site Brendt has shared some of his thoughts about why he sees the service locator design pattern as an anti-pattern and harmful to your overall application.

As a Laravel , I’m confronted daily with the pattern. Every facade call and several helper functions are built upon it.

[…] During a discussion with my colleagues, I found it difficult to put into words what exactly is wrong with grabbing things out of the container – a service locator – so I decided to write my thoughts down, with an example. […] I want to highlight three problems with this approach, directly caused by the use of a service locator.

He goes through a list of where he sees the use of the service locator functionality causing problems including:

  • getting runtime instead of compile-time errors
  • obfuscation of actual functionality
  • increased cognitive load

He ends the post with a quick suggestion on how to solve the issue: use actual dependency injection instead of "magic" locators.



Source link
thanks you RSS link
( http://www.phpdeveloper.org//26461)

LEAVE A REPLY

Please enter your comment!
Please enter your name here