Inversion of Control Containers and the Dependency Injection pattern
Wow I must have been really busy that I completely missed this excellent discussion by Martin Fowler. Actually I have to thank Ben Wilson for using proper terminology which caused me to stumble across this wonderful discussion of PicoContainer and Spring.
While both are Java based implementations, their root cause is universal. I’m glad to see further discussion and materials on this nifty approach. For the past six months I’ve just been calling the approach that Ben used “That Provider Pattern Thing”. Yep its a technical term alright.
UPDATE:
I love a good controversy. And today I received an email from Dan – another buddy – who has been doing Java for umpteen years. Here is his take on the story above:
Okay, *now* you’re getting me started (today’s WagnerBlog post). If there’s any single term that is the poster child of buzzwording gone awry, it’s “Dependency Injection”. Fowler went out of his way to top the already ridiculous term “Inversion of Control”.
“Inversion of Control”? Please. It’s simple class substitution. Java was doing this in 1995.
Hey folks, you want a fancy IoC container? Here’s your fancy IoC Container in 5 lines of code:
1. Properties props = new Properties();
2. props.load(new FileInputStream(”myfancyinjectedclasses.properties”));
3. SuperTerrificInjectedClass superFancy = (SuperTerrificInjectedClass)Class.forName(
props.getProperty(”superTerrificClassName”));
4. superFancy.doSomething();
…okay, 4 lines of code.
Ooooh. Geeeeee. Let’s give it a fancy name and write multi-volume books about it! Let’s name an entire wing of the Smithsonian after this profound discovery, perhaps the most significant since
Special Relativity, (or, shall we now call it “Inversion of Matter to Light and Speed Injection”?)
Oooooooh.
Look, Spring is just dandy. It provides a ready-made XML-based class substitution container (I don’t want to use that other term), a more flexible MVC framework than Struts, good integration
of existing OSS projects like Hibernate, nice shortcuts for stuff like Web Services, and
just enough AOP to put that useless buzzword-laden technology on one’s resume. But all of the drooling over this latest buzzword du jour is really obnoxious, and has reached a new low with this lame “Dependency Injection” term.
If there’s anything I hate about this line of work, it’s the inability of its practitioners to call a duck a duck. Maybe it’s a form of self-preservation–collectively attempting to exclude others by intimidating any potential new competition with high-minded academia; but from where I
stand, it’s just plain silly.
…but don’t get me started.
Dan
Comments
Write a comment
You need to login to post comments!
Comment from Ehsan
Time July 16, 2007 at 11:46 pm
Well said. Except that patterns and more abstract concepts are there for the better understanding of a problem and its solutions so we can later on apply the same solution with less hassle. So although to an experienced designer such as yourself it may seem redundant for the vast majority of people its a very good learning point.