Re: accessor question
Re: accessor question
- Subject: Re: accessor question
- From: Dennis Munsie <email@hidden>
- Date: Thu, 27 Feb 2003 16:41:30 -0500
Well, personally, I think it depends on the application. You should
always make sure that the object is in an consistent state when it's
read from, or when you have it perform an operation. If you only set a
few variables, then you may want to take the approach you mentioned in
your email.
Or, alternatively, you might want to defer it until you actually need
the calculation -- in other words, in one of the read accessors, or any
method which depends on the data you are calculating.
If you do go the "lazy recalculating" method, you might want to have an
internal flag that says that a re-calc is needed. Something like this:
BOOL myNeedsRecalc;
...
-(void)setMyValue(float)aValue
{
myValue = aValue;
myNeedsRecalc = YES;
}
-(float)getMyOtherValue(void)
{
if(myNeedsRecalc) [self recalculate];
return myOtherValue;
}
dennis
On Thursday, February 27, 2003, at 03:15 PM, Koen van der Drift wrote:
Just curious, is it considered good programming practice to add some
code to an accessor that tells an object to update itself, for
instance:
_______________________________________________
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.