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.
[R30;] 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. [R30;] 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.
thanks you RSS link