Re: Design Question: Pro & Cons of KVC/KVO
Re: Design Question: Pro & Cons of KVC/KVO
- Subject: Re: Design Question: Pro & Cons of KVC/KVO
- From: Ken Thomases <email@hidden>
- Date: Thu, 21 Aug 2008 18:12:23 -0500
I have some quibbles...
On Aug 21, 2008, at 12:54 PM, Erik Buck wrote:
So, in summary, the whole point of KVC is to standardize the way an
object’s properties are accessed regardless of how they are stored.
Well, the real point, to my mind, is to increase the dynamism of
property access. It's to allow properties to be accessed using data
to select the property rather than code. Data that is determined at
runtime or design time (IB).
KVC also provides support (hooks) for change management so that any
change to a property can have application defined side effects like
registering an undo event or validating the change.
Hooks other than the accessors it might invoke? I'm not aware of that.
KVO
Key Value Observing takes advantage of the change management hooks
provided by Key Value Coding in order to notify other interested
objects whenever an observed property changes.
Again, I don't think KVO takes advantage of existing hooks. It adds
those hooks by generating subclasses dynamically and isa-swizzling.
Unless and until you add a KVO observer to an object, it doesn't have
any hooks.
KVO is also the basis of “Bindings”. I would go so far as to say
“Bindings” are just a way to specify which objects observe which
properties in which other objects using Interface Builder instead of
writing code to register all those notification observers.
Bindings do more than merely set up KVO observations. The classes
which support bindings also determine what to do when changes are
observed.
Although KVO is “built upon KVC”, KVO really only needs change
notifications. So, if you provide the change notifications, KVO
will work even if you don’t really use KVC.
I don't think that's true. KVO relies on KVC. How else can a KVO
change notification include the old or new value? KVO will perform a
KVC query for will/didChange... messages (including the implicit,
automatic invocations of will/didChange... performed in the hooks it
installs).
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