Advantages of Dependency Injection

I'm planning to know the benefits of dependency injection. 

1.Separate of responsibility:-
Dependency injection does not reduce complexity, but it increases maintainability through separation of concerns and reduced coupling.
2.Loosely couple architecture:-
Dependency Injection is only a means to an end. Even if you never intend to replace your database and even if you never want to write a single unit test, DI still offers benefits in form of a more maintainable code base. The loose coupling gives you better separation of concerns because it allows you to apply the Open/Closed Principle.
3.Configuration and code is separate:-
As well as setting up the services using JAVA you can also use configuration files. This allows you to use XML to write the definitions for the services rather than using JAVA to define the services. In anything but the smallest applications it make sense to organize the service definitions by moving them into one or more configuration files and coding may also separate.

4.Using configuration, a different implementation can be supplied without changing the            dependent code.
5.Testing can be performed using mock objects.

 

0 comments:

Post a Comment