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.
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.
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 ..
... 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 ..
Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com