wood burning stoves 2.0*
The moose likes OO, Patterns, UML and Refactoring and the fly likes DI vs IoC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "DI vs IoC" Watch "DI vs IoC" New topic
Author

DI vs IoC

Mourouganandame Arunachalam
Ranch Hand

Joined: Oct 29, 2008
Posts: 396
Hi Dhanji,

Could you please share your view on DI vs IoC? How these terminologies are related?

Thanks & regards,


Mourougan
Open Source leads to Open Mind
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686



===Vyas Sanzgiri===
My Blog
Sandeep Awasthi
Ranch Hand

Joined: Oct 23, 2003
Posts: 597
In short, IOC is generic term which includes dependency injection and dependency lookup, while dependency injection is concrete form of IOC. In most of the places they are used interchangeably. But fact is IOC is generic and DI is concrete.


Sandeep
Dhanji Prasanna
author
Ranch Hand

Joined: Aug 30, 2009
Posts: 38
Hello, I have answered the question here:
http://www.coderanch.com/forums/posts/list/460611#2055756


Software Engineer at Google

http://twitter.com/dhanji
Mourouganandame Arunachalam
Ranch Hand

Joined: Oct 29, 2008
Posts: 396
Vyas Sanzgiri wrote:


why ?
Mourouganandame Arunachalam
Ranch Hand

Joined: Oct 29, 2008
Posts: 396
Thanks Sandeep & Dhanji for your time.

Klaus Schultz
Greenhorn

Joined: Aug 29, 2009
Posts: 15
To add a historical point: Inversion of Control is a general term first used to explain how OO frameworks work. Inversion of Control is often pronounced as the Hollywood principle "don't call us, we will call you". Take for example the design pattern "Template method": your code is called from the framework. This design pattern shows also the big difference in this meaning of IoC versus DI: the Template Method calls your code at a specific point in a sequence of actions done by the framework. DI as I know it is completely static, constructing a net of objects at initialization time and injecting this environment into the components which need it.

DI is clearly a form of IoC but a very special one.

Dhanji, do you agree this? (besides my crude characterization of DI)

Klaus


Klaus
SCBCD 93%
Dhanji Prasanna
author
Ranch Hand

Joined: Aug 30, 2009
Posts: 38
Klaus,

There are many nuanced interpretations of the differences between them. As I said in my linked post above, I try to avoid IoC altogether as it tends to apply too broadly, and stick instead to DI which everyone is rather clear on (or hopefully can be convinced so!)

Dhanji.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DI vs IoC
 
Similar Threads
Struts Vs Spring
IOC Vs DI Vs Factory Pattern
Depengency injection and IOC
Spring AOP Vs Spring IoC/DI
Cairngorm vs. PureMVC?