2 ms·
Nice article. Never written much JavaScript myself, but as an Objective-C / iOS developer I understand the delegation part well, as it's an integral part of App
by wsc981 14y ago
Nice article. Never written much JavaScript myself, but as an Objective-C / iOS developer I understand the delegation part well, as it's an integral part of Apple's UIKit and AppKit API's. Though the concept was kind of alien to me before I started writing Objective-C code.
A few years ago, when I started learning Objective-C I used a book written by Aaron Hillegass. I liked the way he explained delegation vs. subclassing:
> 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 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 (delegate), 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 to extend the man's brain into a fighting machine. This is the approach taken by many object-oriented frameworks.
Source: Cocoa Programming for Mac OS X by Aaron Hillegass.