[Adium-devl] Category instead of protocol

Peter Hosey boredzo at gmail.com
Wed Apr 18 21:52:19 UTC 2007


On Apr 18, 2007, at 14:20:29, Christopher Harms wrote:
> Well, what I have been told about protocols is, that a class, which  
> should conform a protocol, doesn't have to implement the methods  
> from the protocol - it can.

This is incorrect. Until Leopard, all methods in a protocol are  
*mandatory*. You MUST (in RFC language) have them, or you have not  
fulfilled your promise to conform to the protocol.  
(conformsToProtocol: will still return YES, simply because you said  
you do, but you can expect breakage.)

> That depends on the class, which is performing conformsToProtocol:  
> (or not) in the end. It also depends on using a formal or an  
> informal protocol.

An informal protocol is a “protocol” that is faked using  
categories in order to have optional methods. This sort of thing will  
start to go away after Leopard.

> And about categories I've been told that they expand the given  
> class about methods, which are useful to habe for the given class.

Functionally, yes, but technically a category is just that—a  
category. For example, you might have your creation methods in the  
CreationMethods category, and your conversion-to-various-formats  
methods in the ConversionMethods category.

Usually, though, categories are used in either of two ways:
⁃ to bolt on extra methods
⁃ to define an informal protocol (usually when the category is  
applied to NSObject)
___________________________________
\ Peter Hosey / boredzo at adiumx.com
PGP public key ID: C6550423 (since 2007-01-01)


-------------- 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/8919c8a7/attachment.sig>


More information about the devel mailing list