On The Rails

November 12, 2004

IOC comes to town

Dave Thomas (the Pickaxe forger) explains in plain simple English what Dependency Injection (DI) and Inversion of Control (IOC) can do for an implementation that uses RoR.

I'll admit I read Jamis' article (see Rails, Injected) after picking it up from the wiki yesterday but, not being a true propellerhead, I was left scratching my head wondering what to make of it.

Dave distills it down to this: IOC means the controller is not so tightly coupled to the model.

What does this mean? Well, unit/ functional testing of a controller is easier, as a mock class can be substituted by the DI framework (in this case, Needle) at runtime. Also, your datasources are more flexible as different (non-AR) backends can used in place of certain models, but not others. Shared services and application configuration are more intuitive and flexible, even dynamic (ie. application logic can contribute to the configuration, like "an object can add itself to an array of parties that are interested in being notified of some event"). Very nice.


  • I read it a few times and still never really understood it. Probably as I dont have a Java background. (I detest c++ + java and I semi liked C# but ugh.. anyway).

    I think you need to have a java background to fully comprehend it all...

    By Blogger MadAussie, at 13 November 2004 at 18:41  

  • Hmm, I've gotta say I'm not propeller head either MadAussie, and I'm certainly no Java expert (although I have to admit I'm also a proud lad from Down Under). That said, most things in Jamis' and Martin's articles made sense for me, conceptually at least.

    What is it that you had difficulty with?

    Between myself and the alpha-geeks who listen in occasionally, we may be able to help...

    By Blogger RoRy, at 14 November 2004 at 20:00  

  • This comment has been removed by a blog administrator.

    By Blogger RoRy, at 14 November 2004 at 21:06  

  • No real issues per se. Its just a huge decoupling. Like trying to hide a flaw in OOnes. Like Class A needs to talk to B but they are two different branches of the object heirachy tree type deal.

    Ive also been looking at Rails and again not all that conviced just yet (wont take much pushing!!). Im waiting to see a good example that uses complex multitable design where adding a record touches half a dozen tables. All the examples Ive seen use some very simple table design.

    mm 3rd normal form.. gotta love normalisation...

    By Blogger MadAussie, at 15 November 2004 at 16:28  

Post a Comment

<< Home