Inversion of What?

We've been asked a few times why we didn't use "IOC" or an "IOC framework" for the example code in Growing Object-Oriented Software, Guided by Tests. I have to admit, those questions hit my "pedantic about correct use of technical terminology" nerve!

I'm afraid I'm old enough to remember what IOC really means. And in my day it didn't mean "knowing what constructors are for" or "avoiding the new keyword will magically make code easier to maintain as long as you never need to understand its dynamic dependencies". Inversion of Control means event-driven I/O, in contrast to having a main loop that polls the I/O devices. Think of the difference between DOS and Windows programming (or curses vs. X11 for Unix programmers). In DOS you had to write a main loop that queried the position of the mouse and state of the keyboard. Windows turned that around: it manages the input devices and calls your program's event handler procedure when the user performs some input. So Windows inverted the program's control flow compared to DOS: it called into the application when input occurred rather than the application calling out to query device state .

So, GOOS only uses the Inversion of Control pattern: the Smack library delivers XMPP messages to the application through a callback and Swing delivers user input events through callbacks.

But I'm being (slightly) facetious. The term IOC is being used in its recent (mis)usage to mean Dependency Injection. But I'll whinge about address the Dependency Injection question another time.

Image copyright © 2010 H Matthew Howarth. Used under the Creative Commons Attribution 2.0 Generic license.

Copyright © 2011 Nat Pryce. Posted 2011-01-06. Share it.

Comments powered by Disqus