Thursday Night

Paul Betts’s personal website / blog / what-have-you

A powerful UI programming metaphor from Aaron Hillegass

Once upon a time (before Baywatch), there was a man with no name. Knight Industries decided that if this man were given guns and wheels and booster rockets, he would be the perfect crime-fighting tool. First they thought, “Let’s subclass him and override everything we need to add the guns and wheels and booster rockets.” The problem was that to subclass Michael Knight, you would need to know an awful lot about his guts so that you could wire them to guns and booster rockets. So instead, they created a helper object, the Knight Industries 2000 Super Car, or “Kitt”.

Notice how this is different from the RoboCop approach. RoboCop was a man subclassed and extended. The whole RoboCop project involved dozens of surgeons who extended the man’s brain into a fighting machine. This is the approach taken with many object-oriented frameworks.

While approaching the perimeter of an arms dealer compound, Michael Knight would speak to Kitt over his watch-radio. “Kitt”, he would say, “I need to get to the other side of that wall.” Kitt would then blast a big hole in the wall with a rocket. After destroying the wall, Kitt would return control to Michael, who would stroll through the rubble.

– from Cocoa Programming for Mac OS X, by Aaron Hillegass

Even if you don’t care about programming on the Mac, you should take a look because the developers at NeXT were really ahead of their time when they created the Cocoa framework. Objective C is like the “metal” version of Ruby, especially when you look at features in Obj-C like how their vtables are structured and their emphasis on introspection and mixins (called “categories” in Obj-C), and Cocoa takes full advantage of these features to make a really elegant, reusable UI framework.

Written by Paul Betts

September 22nd, 2007 at 1:38 pm