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: Jay Kuri <email@hidden>
- Date: Tue, 26 Feb 2002 21:05:16 -0600
Thanks for the info... just a couple more questions...
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.
Ok... In the particular situation I'm thinking of the object sending the
messages (or posting the notifications) is part of a network-messaging
framework. The object that should be informed of the new 'request'
message arriving will not be known when I write the framework... and
different types of messages could have different object handlers.
Again, this would vary depending on the app.
The two ways I can see doing it are:
1) The app registers one (or several) of it's objects to receive
notifications and the framework builds the notification names
dynamically.
or 2) Have the framework use a dictionary or other container holding a
series of (id *)'s and using an informal (or formal) protocol to deliver
the messages via method calls. (of course, the objects would have to
register themselves with my object in this case)
The simplicity of implementing the notification method appeals to me...
and the way the network-messaging protocol works is very analogous to
notifications in cocoa... (requests arriving that may or may not cause
something to happen, depending on the app) It seems like Notifications
are a natural interface... what I'm trying to figure out is: is this a
'bad' way to use notifications? are they too slow to be useful for
processing this kind of input?
How would you do it?
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.
This is acceptable, I wouldn't want the framework object to do
anything with messages the app didn't want to deal with.... In fact, the
framework object wouldn't dispatch messages the app didn't say it
wanted, regardless of how it was implemented.
Thanks again,
Jay
_______________________________________________
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.