Re: Copying Notification Dictonaries & sortingUsingSelector problems
Re: Copying Notification Dictonaries & sortingUsingSelector problems
- Subject: Re: Copying Notification Dictonaries & sortingUsingSelector problems
- From: Charles Jolley <email@hidden>
- Date: Wed, 26 Jun 2002 12:46:48 -0500
Hi Alex:
On Wednesday, June 26, 2002, at 11:05 AM, <email@hidden> wrote:
Charles, Thanks! Wow, you made me learn a lot and I will certainly
correct the mistakes made here. It will for sure help to make my app a
little bit less leaky, I mean not leaky at all of course ;-)
yeah, I wish my projects had no leaks!
<Snipped a few comments to keep e-mail short>
... it looks like you want
docMenuItemExperiments to hold a copy of the dictionary. If >
you kept JUST the object passed and the object is mutable, it
could change underneath you.
Would this be a good idea in this situation, just keep it since the
sender object is the only one changing the contents of the dictionary?
Or is it wiser and/or safer to copy the contents anyway.
I generally try to design my objects so they are "loosely" coupled
whenever it seems appropriate. In other words, I try to reduce the
number of other classes a given object is dependent on. This makes it
much easier to incrementally update the application over time.
Notifications are Cocoa's Way of loosely coupling objects. Sharing an
instance of a mutable object is the ultimate way to tightly couple
objects. In most circumstances, this is very bad design.
I would suggest you have your object generate a new dictionary and post
a notification to the doc menu controller. This is cleaner and just as
fast since you would effectively have to rebuild the dictionary anyway
even if you were using a mutable dictionary.
Also, remember that Cocoa is very nice about working with nil objects.
When you initialize your doc menu controller, you could probably leave
your doc menu dictionary as 'nil'. It will act just like an empty
dictionary in most circumstances. (Not always though, YMMV).
Cheers,
-C
_______________________________________________
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.