File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Have I achieved dependency Injection?

 
Hendra Kurniawan
Ranch Hand
Posts: 239
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still confused with the concept DI. In a nutshell, I perceive that DI is basically only aims to loosen coupling. Some help here? thanks
 
Ran Pleasant
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hendra Kurniawan wrote:I'm still confused with the concept DI. In a nutshell, I perceive that DI is basically only aims to loosen coupling. Some help here? thanks


It's not the only goal, but it is the major goal. Another major benefit of DI is being allowed to write code without having to worry about where other objects are coming from. For exmaple, you can write a service that uses a couple of DAOs without having to think about creating or getting the DAOs. The field type for each DAO would be an interface and the intefaces would be implemented by whatever objects are injected. This allows you to unit test your service using dummy DAOs that implement the interfaces and then later implementing the DI with the actual DAO objects and doing your integration testings.

And that is why I love Spring!
 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 205
1
Android Flex Google App Engine
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coupling refers to the degree of direct knowledge that one class has of another. The less your components are tied to each other, the better. Using a DI framework has many benefits -
Dependencies are handled through the provider framework making your application code more flexible, reusable and scalable.
Using a DI Framework to manage the singletons in your applications. Singletons without a DI framework may hamper your testing.
Encourages the Program to interfaces approach.
Makes for an excellent architectural glue providing consistencies in how you would configure JDBC, JMS, Javamail, JNDI and any other API's.

 
Jayr Motta
Ranch Hand
Posts: 110
Google App Engine Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dependency Injection is an awesome concept and we could talk about lots of benefits that it brings! This improves the cohesion once the code instead worry getting/instantiating objects they just do what they need to do ..

Ran said:
... The field type for each DAO would be an interface and the intefaces would be implemented by whatever objects are injected. ...


This will improve either on modularity of your software, i could say that your software is healthier ..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic