[Adium-devl] Category instead of protocol
Evan Schoenberg
evan at adiumx.com
Wed Apr 18 20:48:40 UTC 2007
On Apr 18, 2007, at 9:16 AM, Christopher Harms wrote:
> I don't want to start a discussion in the ticket system nor the
> mailing list (but you can cc: them, if you like), so I'd like to
> ask you personally:
> In ticket #5129 (http://trac.adiumx.com/ticket/5129) you suggested
> to create a category for NSObject instead of making a protocol.
> Well, I have to admit that I'm not that firm in Objective-C to see
> all advantages and disadvantages of the two ways. But this
> situation I would prefer a protocol, because I think this is the
> most common way, isn't it? And additionally, it doesn't really make
> sense for a NSObject to respond the OutlineView-calls (even if the
> WindowController-class is a direct or indirect subclass of NSObject).
I'll cc the list in case this of interest to anyone else.
Protocols are a set of methods which a conforming class must
implement in their entirety. The class should declare that it
conforms to the protocol in its interface declaration with <Foo>.
Categories on NSObject should be used to declare the methods which
NSObject may respond to; -[NSObject respondsToSelector:] should be
used before the actual call to verify the object does respond to it.
If you wanted to have a required set of methods for a delegate, a
protocol -- and then requiring that an object conforming to that
protocol in setDelegate: -- would be appropriate. That's very rarely
the case, though, and isn't in this one.
All Apple delegate methods of which I'm aware are declared as
categories on NSObject. For example, NSOutlineView.h says:
@interface NSObject(NSOutlineViewDelegate)
/* NSOutlineView replacements
*/
- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)
cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item;
- (BOOL)outlineView:(NSOutlineView *)outlineView
shouldEditTableColumn:(NSTableColumn *)tableColumn item:(id)item;
- (BOOL)selectionShouldChangeInOutlineView:(NSOutlineView *)outlineView;
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)
item;
- (BOOL)outlineView:(NSOutlineView *)outlineView
shouldSelectTableColumn:(NSTableColumn *)tableColumn;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3
- (void)outlineView:(NSOutlineView *)outlineView
mouseDownInHeaderOfTableColumn:(NSTableColumn *)tableColumn;
- (void)outlineView:(NSOutlineView *)outlineView didClickTableColumn:
(NSTableColumn *)tableColumn;
- (void)outlineView:(NSOutlineView *)outlineView didDragTableColumn:
(NSTableColumn *)tableColumn;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
/* tool tip support
When the user pauses over a cell, the value returned from
this method will be displayed in a tooltip. 'point' represents the
current mouse location in view coordinates. If you don't want a
tooltip at that location, return nil or the empty string. On entry,
'rect' represents the proposed active area of the tooltip. By
default, rect is computed as [cell drawingRectForBounds:cellFrame].
To control the default active area, you can modify the 'rect' parameter.
*/
- (NSString *)outlineView:(NSOutlineView *)ov toolTipForCell:(NSCell
*)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:
(id)item mouseLocation:(NSPoint)mouseLocation;
/* Optional - Variable Row Heights
Implement this method to support an outline view with
varying row heights. The height returned by this method should not
include intercell spacing and must be >0. Performance
Considerations: For large tables in particular, you should make sure
that this method is efficient. NSTableView may cache the values this
method returns. So if you would like to change a row's height make
sure to invalidate the row height by calling -
noteHeightOfRowsWithIndexesChanged:. NSTableView automatically
invalidates its entire row height cache in -reloadData, and -
noteNumberOfRowsChanged.
*/
- (float)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:
(id)item;
#endif
/* NSOutlineView specific
*/
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)
item;
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldCollapseItem:
(id)item;
- (void)outlineView:(NSOutlineView *)outlineView
willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)
tableColumn item:(id)item;
@end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20070418/a7e218e2/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20070418/a7e218e2/attachment.sig>
More information about the devel
mailing list