Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???
Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???
- Subject: Re: Cocoa Bindings - nondebuggable, non-obvious, procedural ???
- From: mmalcolm crawford <email@hidden>
- Date: Mon, 3 Jan 2005 10:36:04 -0800
On Jan 3, 2005, at 4:44 AM, Izidor Jerebic wrote:
First:
[calculator add:someNumber] ;
Second:
val = [calculator value] ;
newVal = val + someNumber ;
[calculator setValue:newVal] ;
What you've done has completely lost the encapsulation of the 'add'
method to the calculator object.
You can still use [calculator add:someNumber], but inside the 'add'
method you would do:
- (void) add:(float)addition
{
float newValue = [self value] + addition;
[self setValue:newValue forKey:@"value"];
}
Exactly. What I have done in the [second] example is really wrong.
But, as you can see, it is easier to get bindings working that way. So
if you write bad, un-encapsulated code, it is easier to use bindings.
This is the harm I was talking about.
It's not clear what is wrong with Tim's suggestion. If you implement
add: as he proposes, then your first example works as required.
If anything, to me bindings encourages you to write good,
well-encapsulated code. If you want to minimise your own code, you use
automatic KVO notification, which relies on you using standard accessor
methods, rather than changing instance variables directly...
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden