Inversion of Control (IoC / Dependency Injection) for Dummies [closed]?

Think of Dependency Injection/Inversion of Control as little more than a big object factory, a declarative, configuration-driven virtual constructor. Instead of littering your code with calls to "new" that hardwire the concrete type that your client class uses, you're now going to have that virtual constructor instantiate objects for you. What's the advantage that all that complexity is buying you?

Object creation is now a declarative thing. If you happen to base your design on appropriate interfaces, you can ask the the object factory to create a proxy that implements the same interface when it's convenient. All kinds of good things are now possible: aspect-oriented programming, transparent remoting, declarative transactions, etc.

1 Thanks, I'm gonna look forward to learning this pattern. Seems very useful. – Diego AC Dec 20 '10 at 3:33.

Simple answer: It lets you hand in the "things" that any given object will use to do its work. Contrived Example: Say the object wants to get the time for some purpose, you hand it a "ITimeService" and it calls "GetTime" on that. The purpose of this is to "de-couple" the class from having hard relationships to things you may not wish it, and to aid testing.In my humble opinion some people go a little overboard, but the testing argument is a valid one, and certainly it's an approach that is useful to adopt at times.

More involved answer: Martin Fowler on Inversion of Control.

Diego: I've not specifically scene the thing you are referring to, but from applying the general principal it would mean that the Repository (i.e. Place to get data) is passed to all classes requiring it; with the view that you can swap it between a TestRepository a TextFileRepository or SomeOtherTypeOfRepository. – Noon Silk Dec 19 '10 at 21:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions