jump to navigation

Inversion of control/Dependency Injection June 24, 2005

Posted by javafoo in IOC/Dependency Injection, javanotes, Spring.

A very interesting way of looking at Inversion of Control by Craig Walls in his Spring in Action Book:
“You can think of IoC as JNDI in reverse— instead of an object looking up dependencies from a container, the container gives the dependencies to the object at instantiation without waiting
to be asked.”

Article by Martin Fowler.

This is from an article on Spring Framework by Benoy Jose, for quick reference.

There are three types of Dependency Injections.

  • Type 1 IOC also called Interface Injection In Type 1 IOC the injection is done though an interface. The interface will define the injection method and the implementation class has to implement this interface and provide concrete implementation for the injection method. Pico Container uses this.
  • Type 2 IOC also called Setter Injection In Type 2 IOC the injection is done via a setter method. Type 2 IOC uses setter methods to get the dependent classes it needs. Spring uses this.
  • Type 3 IOC also called Constructor Injection. In Type 3 IOC implementing class defines a constructor to get all its dependents. The dependent classes are defined in the constructor arguments. Avalon uses this.


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: