Incidental Inversion of Control

This morning I started reading about the Spring Framework and, as usual, I followed a rabbit hole to learn what the phrase Inversion of Control (IoC) means. IoC is also known as the Hollywood Effect ("don't call us, we'll call you"). A lot of programming frameworks use an inversion of control to take care of the bulk of the work and leave your code to perform its task (and only its task).

Most web frameworks are a good example of IoC. In Java web applications, the framework takes care of all HTTP complexities and turns control over to your servlet or JSP when the time is right. This leaves your JSP to process the request and return a response - easy! The ASP.NET framework has an excellent inversion of control with its postback model. The framework allows for applications to be built very similar to Windows applications - the underlying framework takes care of display issues and calls parts of the applications code when the time is right. A lot of these calls to code are handlers for events like Click, Load, and others.

As I read about this "new" concept I began to realize that it wasn't new at all. ASP.NET and J2EE use it extensively. In fact, I have created such a framework without realizing what I created. In the middle of last year I created a pluggable scheduler interface for our eQube environment that allows the programmer to simply specify report names and filter values via XML, and when it comes time to do something special, the programmer can hook into events and have the framework execute some JavaScript code to do something special.

I stumbled into creating this framework after doing several short projects that required some boilerplate code to interface with the eQube APIs. It all happened quite innocently, but having taken the incidental route to IoC framework I have gotten much more value than I thought I would. For instance, it is suddenly very easy to run a report with 400 different filter configurations. I just put together some XML to spec the report and throw in a block of JavaScript to change the filter values. The inversion of control takes away most of the responsibility and leaves me to do my job, and only my job.

After today's lesson in inversion of control, I'm brainstorming new ways to use it. Perhaps even consolidating my other code into the scheduler framework, or maybe integrating it with the spring framework. As always, there's power in doing less.