From being dependent to dependency injection
05 May 2014
This post shows how dependency injection makes life easier. The post starts off showing a service class using a hard coded dependency. Next the service class uses a factory to be able to change the specific locator implementation dynamically. And finally dependency injection is used to inject the dependency into the service.
The interface CompanyLocator defines a method retrieveAllCompanies which is implemented by WebCompanyLocator.
The CompanyService uses a hard coded locator dependency. There is no way to change the locator implementation.
The CompanyFactoryService uses a factory to get a hold of the locator implementation.
The CompanyDIService uses dependency injection to inject a specific implementation into the service.
blog comments powered by Disqus