Re: NEWBIE: Why use protocols?
Re: NEWBIE: Why use protocols?
- Subject: Re: NEWBIE: Why use protocols?
- From: Ondra Cada <email@hidden>
- Date: Wed, 18 May 2005 21:03:49 +0200
Ben,
On 18.5.2005, at 20:32, Ben D. Jones wrote:
The reason I ask is that I'm actually starting on a very large
project (my first big project) in Cocoa. Having done large
projects in C I'm not a newbie to programming, just Cocoa. So in
what cases (example of use) would it be needed or proper to use
protocols?
Never really needed (but for a few very specific cases like if you
want to supply method signatures to limit the round trips with
Distributed Objects).
Proper... well, that's a question which, I guess, different
programmers would answer in different ways.
Anyway: if you very strongly feel a need to formalise a set of
methods, which make sense only as a complete set (i.e., the very
opposite from the delegate methods!), and which may be implemented by
a number of unrelated classes, consider formal protocols.
Though, be wary that there are some gotchas. As the Apple
documentation says: "Formal protocols have their limitations. If the
list of methods declared in a protocol grows over time, adopters of
the protocol would become non-conforming. So formal protocols in
Cocoa are used for sets of methods that are stable, such as NSCopying
and NSCoding. If you anticipate growth in the set of protocols
methods, declare informal protocols instead of formal protocols."
Myself, I've been declaring *heaps* of formal protocols fifteen-odd
years age when I started learning ObjC. Today, I hardly ever use them :)
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden