Re: notifications vs delegates (was: The fuzzy aspects of Cocoa)
Re: notifications vs delegates (was: The fuzzy aspects of Cocoa)
- Subject: Re: notifications vs delegates (was: The fuzzy aspects of Cocoa)
- From: "John C. Randolph" <email@hidden>
- Date: Tue, 26 Feb 2002 17:45:53 -0800
On Tuesday, February 26, 2002, at 05:03 PM, Jay Kuri wrote:
Your specific question about notifications vs. delegates is
answered in a
Stepwise article:
http://www.stepwise.com/Articles/Technical/2000-03-03.01.html
I read this and another at cocoadevcentral and I have a
question. The stepwise article implies that notifications are
slower than a delegates... (relating to looking up in a hash
table vs just using the selector) my question here is: how
much slower are they?
Considerably.
does it really make enough of a difference to choose one over
the other in 'normal' situations?
I've never measured it, but notifications are snappy enough for
things like updating an inspector panel when a selection
changes. I wouldn't use notifications for something like an
animation timer, though..
The one thing I didn't notice is when to use one over the other
if you are not looking for possible veto (close window example).
Use a notification if you want to let anyone who cares sign up
to get the message. Use a delegate when you need some other
object to tell you what to do.
Suppose you have an object (part of a framework) that wants to
deliver a small chunk of data to an interested object.
Normally, this data would only be of interest to a single
object... is there a reason to choose delegates over
notifications or vice versa?
Well, in this case, you would probably just send a message to
that interested object. A delegate is an object that tells you
how to modify your behavior.
From what I gather, notifications are a bit more flexible in
terms of dynamic messages (notifications with names that are
defined at run time) but delegates are faster...
Yes. When you post a notification, you don't need to know or
care if anyone's listening for it.
Is there a way that is more 'correct' in terms of the purposes
that each are intended/designed for?
Use the one that fits..
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.