Cocoa Bindings: Keys vs Ivars

There was a topic that came up on cocoa-dev last night regarding Cocoa bindings. Specifically, the question was since the bindings system directly manipulates data, where do you enforce app-specific data rules (aka business logic)?

I can see why people think of bindings as directly manipulating data, but really that's just one option available to you. Bindings asks for and provides values by key. That key can map to a instance variable or not. For example, if you bind something to 'name', your accessors might look like this:


- (NSString *)name;
- (void)setName:(NSString *)name;


Now, behind those accessors could be an instance variable called name. But it could just as easily be a dictionary or a delegate method.

Not to mention all the other options you have with key-value validation and NSValueTransformer.

And if you really need fine-grained control, you can override the individual binding methods or -valueForUndefinedKey.
Design Element
Cocoa Bindings: Keys vs Ivars
Posted Sep 29, 2004 — 0 comments below




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015