This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes IOC Vs DI Vs Factory Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "IOC Vs DI Vs Factory Pattern" Watch "IOC Vs DI Vs Factory Pattern" New topic
Author

IOC Vs DI Vs Factory Pattern

Bhairava Surya
Ranch Hand

Joined: Aug 19, 2007
Posts: 45
Hi All,

I am new to Spring concepts. As I read IOC, I am confused what wrong with Factory Pattern that we are going for this IOC Pattern(hope this is also a pattern).

Please provide some basic examples for IOC/DI/Factory Pattern with their differences.

Thanks & Regards,
Ravi.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Inversion of Control (IoC) and Dependency Injection (DI) usually refer to the same thing. IoC is a more general concept (instead of doing X itself, a class relies on some other class to do it) DI is IoC as applied to dependent classes (instead of creating a class that I depend on, it will be passed to me). DI is the most common use of IoC, so usually when they are discussed the terms are used interchangeably.

The Factory Pattern's main concern is creating things - DI's main concern is how things are connected together.

In practice, these two concerns (creating and connecting) are usually related, so most DI/IoC containers do both. You could think of most implementations as very configurable factories - but because the implementations address both concerns - not because the Factory pattern and DI/IoC are the same.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

And it isn't an OR thing. I can have Factories and still use IOC/DI

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IOC Vs DI Vs Factory Pattern
 
Similar Threads
DI vs IoC
IOC and problems
SCEA Assignment: JSF Vs Struts
Spring -> Factory Design Pattern / IOC/DI ?
Factory Vs Abstract Factory