Re: Bindings paradigm
Re: Bindings paradigm
- Subject: Re: Bindings paradigm
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 10 Jul 2004 13:41:53 -0700
On Jul 10, 2004, at 1:18 PM, Gwynne wrote:
I apologize if this message appears on the list twice; I originally
sent it from the wrong email address and I'm pretty sure the list
doesn't accept unsubscribed posters.
I've been working with bindings lately, and I have a question about
design...
Taking an example, I have a button that's only enabled based on the
settings of certain keys within my model object, but the logic can't
be expressed using the multiple-value form of the "enabled" binding
(i.e. it's more complex than an AND on each relevant key). There are
two basic ways to deal with this:
1) Watch for changes to the relevant keys in code and use [NSButton
setEnabled:].
2) Create a new key in the model object that encapsulates all the
logic and returns the BOOL value (or an [NSNumber numberWithBool:], it
doesn't matter as I understand it), and bind "enabled" to that key.
#2 is pretty simple, but to me it seems to violate the principle of
KVC because it doesn't represent any data in the model but rather a
state of the view that would have been the controller's responsibility
before bindings came along.
There's really no principle in KVC that calls for a direct
correspondence between keys and actual data in the model. I've written
a category on NSView, for example, that exposes a binding for "zoom
level". The fact that it's derived from the bounds rect of the view is
irrelevant.
So, it's perfectly kosher to make up a key/value combination that
exposes some combination of state in the model.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.