Re: notifications vs delegates (was: The fuzzy aspects of
Re: notifications vs delegates (was: The fuzzy aspects of
- Subject: Re: notifications vs delegates (was: The fuzzy aspects of
- From: Brian Webster <email@hidden>
- Date: Wed, 27 Feb 2002 10:44:21 -0600
On Tuesday, February 26, 2002, at 11:15 PM, cocoa-dev-
email@hidden wrote:
No. Typically, you should choose the solution that better fits your
situation. The speed of notifications will only be a problem if you're
delivering hundreds of them (at least -- probably more like thousands)
per second. Assuming the method hit by the notification is quick, of
course.
I had some speed problems with notifications in one program I
was writing, but I was able to speed it up by using
NSNotificationQueue, which lets you merge multiple notifications
with the same name and/or object into a single notification.
Another big distinction is the "looseness" of the coupling.
An object
with a delegate must have an explicit (and probably retained) reference
to its delegate.
For the record, delegate objects are actually not typically
retained. This is because in the most common case, your
delegate object that already has a reference to the view object,
so if the view object were to retain the delegate, it would
result in a retain cycle and thus a memory leak.
For example, it is entirely appropriate for an application to have a
direct reference to its delegate. App delegates are typically
singleton
objects created for the sole purpose of "advising" and
"controlling" the
application object and handling top-level application concerns.
Decoupling that relationship would be unnecessary in most cases. (Most
of NSApp's messages are of potentially general interest, however, so
they are *also* provided as notifications in most cases).
The messages that are sent out as notifications are actually
sent to the delegate as notifications as well. When the
delegate is set, NSApplication will add the delegate as an
observer for all the notifications, using the selectors
specified in the NSApplication docs. But any other object can
then come along and listen for the same notifications as well.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
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.