Saturday, August 16, 2008

NSApplication and delegate #2

The only reason for that yucky thing I could think off, is that they wanted to save people from having to define and implement all 14 methods each time a NSApplication delegate was needed, even if only one of them was needed. Since the concept of optional method in a Protocol was only introduced recently in Objective-C 2.0, using a protocol for the NSApplicationDelegate (or for NSApplicationNotifications) was I guess not a solution back when NeXTSTEP was been designed and implemented. Still, having to define and implements a bunch of methods isn't much of a huge burden (copy&paste), likely only a couple of them are going to have a real implementation, and the number of application delegate class per application is mainly, well ... one.

I'm aware that adding methods in Objective-C isn't as costly as adding a virtual method to a C++ class, but still ... this is not a very elegant solution. As this thing used all over the place? I'm a little scare to find out ...

BTW, sorry for the sloppy code formatting on my previous posts. I still haven't figured a nice way to present it with proper indentation. Syntax highlighting will be nice too.

No comments: