On Mar 16, 2009, at 11:20 AM, Stuart Malin wrote:
How does one know just which methods are "required primitive" methods for some class? Is that discernible from documentation? Header file?

They are documented, but the header files also split the primitives from the rest.

Look at NSString:

@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
/* NSString primitive (funnel) methods. A minimal subclass of NSString just needs to implement these, although we also recommend getCharacters:range:. See below for the other methods.
- (NSUInteger)length;                   
- (unichar)characterAtIndex:(NSUInteger)index;
@end

@interface NSString (NSStringExtensionMethods)
- (void)getCharacters:(unichar *)buffer;
- (void)getCharacters:(unichar *)buffer range:(NSRange)aRange;
...
@end

Then, NSMutableString:

@interface NSMutableString : NSString
/* NSMutableString primitive (funnel) method. See below for the other mutation methods.
*/
- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString;
@end

@interface NSMutableString (NSMutableStringExtensionMethods)
- (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc;
- (void)deleteCharactersInRange:(NSRange)range;
...
@end

The primitive or "funnel" methods are all you need to implement. NSString and NSMutableString implement all of the other methods entirely in terms of the primitive methods, directly or indirectly (i.e. some other method may be implemented in terms of another method implemented using only the funnel methods).

You only *need* to implement the funnel methods.

You might, however, find that you need to implement some of the others for efficiency's sake (as implied by the comment in NSString). And that is exactly what concrete subclasses do -- they implement highly optimized versions of the other methods specifically for performance reasons.

Same pattern holds true for the other class cluster classes.

b.bum

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to