Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inversion of control

 
prasad chowdary
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello experts,

In springs the terms Inversion of Control (ioc) and Dependency Injection are same.


thanks in advance.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really, but dependency injection is used to achieve inversion of control.
One could implement inversion of control using a service locator or the factory pattern rather than dependency injection.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can think of the terms as one being a concept and the other an action to put that concept into action.

So Inversion of Control is a concept. Basically saying that one class isn't responsible for creating and getting another class it needs a reference too.

Dependency Injection is the action of another class injecting a dependency into the class that needs it. That is why the poster before me says that there are other actions/patterns that can also be used to implement the concept of Inversion of Control.

Example. SuperMan did not create his own super powers. They were given to him by outside forces. That is Inversion of Control.

If the action was he landed on earth and earth gave him his super powers you could say that is Dependency Injection. But if Superman got his powers by going to a special store/factory and asking for specific powers that the factory creates and injects into him, that is another implementation of Inversion of Control.

The only hero that actually created their own super powers, no one else can do this, is Chuck Norris.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic