@Jerry: I've also noticed a trend among more experienced Cocoa developers is the practice of 'avoiding sub-classing'. I'm not experienced enough to fully grasp why this is the case, but it seems to be the result of a rather primitive IDE (XCode), compared to a product like Visual Studio or Eclipse.
The idea with Cocoa is that you should be able to use existing classes to create new ones rather than subclassing. There are some classes intended to be subclassed a lot (NSObject, NSView, NSWindowController etc) but for the most part you are encouraged to use existing classes.
The other plus of this is you end up with fewer, but more powerful classes. Whereas Java has JButton, JToggleButton, JRadioButton, JCheckBox, Cocoa just has NSButton which does all of these.
@Taz: I suspect delegates can be confusing because they're not used particularly consistently. When designing an Objective-C class, how do you know when you should you use a delegate, a data source (which is a specialized delegate), or a notification? There's no particular rhyme or reason to their use within AppKit itself
Actually they are very consistent. When designing a class it's easy to decide what you need. A data source is when you need to supply data to populate a view. The "hard" thing is delegates vs notifications but it is a simple answer. Delegates are 1 to 1 relationships, notifications are 1 to many. If you want multiple objects to know about an event then use notifications. If you only want one object to know about it, or want something returned then use a delegate.,
by Martin Pilkington — May 17
The idea with Cocoa is that you should be able to use existing classes to create new ones rather than subclassing. There are some classes intended to be subclassed a lot (NSObject, NSView, NSWindowController etc) but for the most part you are encouraged to use existing classes.
The other plus of this is you end up with fewer, but more powerful classes. Whereas Java has JButton, JToggleButton, JRadioButton, JCheckBox, Cocoa just has NSButton which does all of these.
@Taz: I suspect delegates can be confusing because they're not used particularly consistently. When designing an Objective-C class, how do you know when you should you use a delegate, a data source (which is a specialized delegate), or a notification? There's no particular rhyme or reason to their use within AppKit itself
Actually they are very consistent. When designing a class it's easy to decide what you need. A data source is when you need to supply data to populate a view. The "hard" thing is delegates vs notifications but it is a simple answer. Delegates are 1 to 1 relationships, notifications are 1 to many. If you want multiple objects to know about an event then use notifications. If you only want one object to know about it, or want something returned then use a delegate.,