Re: Design Question: Where to observe using KVO?
Re: Design Question: Where to observe using KVO?
- Subject: Re: Design Question: Where to observe using KVO?
- From: Ken Thomases <email@hidden>
- Date: Sun, 13 Jul 2008 10:36:56 -0500
On Jul 11, 2008, at 2:45 AM, Patrick Mau wrote:
Do you think that observing lots of objects with lots
of keypaths is a good idea anyway?
Honestly, I've forgotten the original design issues you're considering.
If you need to observe lots of objects and key paths to achieve your
purposes, then do that.
Of course, it can't hurt to consider some alternatives, like
Notifications. See the Cocoa Fundamentals Guide for some other
possibilities.
One technique with KVO to reduce the number of keys that you need to
observe on an object is to create a new property which acts as a
single thing to observe which stands for a constellation of other
properties. Often, if one object is observing many properties of
another object, there is one abstract concept that it's really
interested in. It's observing the many properties because it has too-
intimate knowledge of the inner workings of the other object -- the
classes are too closely coupled. Instead of the observed object
presenting an abstract concept as a whole thing, it's exposing the
implementation details from which that whole is composed. That forces
the observer to pay attention to all of those details.
In such cases, you should use +keyPathsForValuesAffectingValueForKey:
(Leopard and later) or
+setKeys:triggerChangeNotificationsForDependentKey: (if you need to
deploy to earlier OS versions) to teach KVO which detail properties
comprise the whole-concept property, so change notifications in one
cause change notifications of the other.
Since the number of keypaths for each object is constant, I might
decide using a custom bitmap object as the value part in the
dictionary. That bitmap would indicate which keypath is being
observed.
Sounds like premature optimization to me. *shrug*
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden