Re: theoretical - Protocols
Re: theoretical - Protocols
- Subject: Re: theoretical - Protocols
- From: Todd Blanchard <email@hidden>
- Date: Tue, 29 May 2001 13:50:50 -0700
The main difference is that any class that adopts a formal protocol has
to implement all of the
methods in the protocol. In that respect its like a Java interface or
C++ class with pure virtual
methods. The requirement is compiler enforced.
Where it makes sense, formal protocols are to be preferred because they
serve to lay out the
interaction contract in an explicit way and document for the developers
exactly what is expected of the
implementors of the protocol.
It doesn't always make sense though. For instance, when doing a chain
of command pattern with
delegation, you might not want to require a delegate to implement every
single method you might
be able to send it. You see this most often in event handling
delegation. You might want to allow the addition of a delegate that
responds to keyDown: without forcing the delegate to also implement
mouseDown: and all the rest of the event processing. So an informal
protocol is a better choice here.
BTW, it is my opinion that informal protocols are overused by certain
lazy developers.
Many of these developers write or have written library code for Apple
computer.
Think it through and say what you mean when you program.
On Saturday, May 26, 2001, at 01:10 PM, Bob Savage wrote:
Hi, I'm trying to learn about protocols, but I don't quite understand
something: why are there informal protocols? It seems like the best
thing
would be to use the @protocol mechanism since it exists, but even Apple
doesn't do that sometimes (e.g. "NSTableDataSource informal protocol").
Is
this just being lazy, or is there a good reason to forgo the formal
protocol
definition?
Another question: IF I were to define a protocol for objects that I get
from
3rd parties (via Bundles), where should I define that protocol? Right
in my
".h" file for the Class that uses these 3rd party-supplied objects?
thx,
Bob
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev