What is Inversion Of Control and the Dependency Injection pattern?

Questions by manish_cs00

Showing Answers 1 - 6 of 6 Answers

jwhite1202

  • Jan 31st, 2008
 

Inversion Of Control (IoC) and Dependency Injection (DI) are concepts generally associated with the Spring Framework.  The easiest way to think of Inversion Of Control is what Rod Johnson (founder of the Spring framework) calls the Hollywood Principal, "don't call us we'll call you:.  IoC uses interfaces to acquire and release resources a prime example being JDBC connections.  This also part of the reason Spring works so well with Object/Relational Mapping (ORM) tools such as Hibernate, iBatis, and TopLink.

DI is a more specific version of IoC.  DI pushes application dependencies at runtime.  DI comes in several flavors in Spring:
    1.  Setter Injection - uses Java Bean setters (and getters) to get dependencies
    2.  Contructor Injection - dependencies come from constructor arguments
    3.  Method Injection - where the container is used to implement dependencies

  Was this answer useful?  Yes

PNVRKPrasad

  • Jul 11th, 2009
 

Comment: Dependency Injection is more appropriate name than inversion of control.
Purpose: Achieving polymorphism more flexibly through different server classes
How: Allocating (Injecting) the actual concrete class1 (server) at run time to the class2 (client). Class1 has variations and the configuration file holds the information of which class needs to be injected. Class1 can be replaced by class1A through config file.
Ways: Injecting through class2's constructor, Setter method,..
Examples: Spring, PicoContainer, Avalon
Similar patterns: Service Locator
Final word: Most of the design patterns are there to handle polymorphism requirements. They do it in different ways. Key is to understand the underlying problem/purpose.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions