RE: accessor question
RE: accessor question
- Subject: RE: accessor question
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 27 Feb 2003 16:22:16 -0500
I can't say that there is an always-correct answer to this, but an
alternative you may not have considered is a "convenience method" in the
object which combines common or standard calls, like
- (void)setMyValueAndRecalculate:(float)aValue
{
[self setMyValue:aValue];
[self recalculate];
}
This has the advantage of explicitly saying what is going on inside your
object, and it's more maintainable because you might later determine that
instead of [self recalculate] you sometimes want to [self analyze] or
whatever. On the other hand, if your object by its nature always, always,
always recalculates itself, it may make more sense to put everything in
setMyValue.
Jonathan
>
>
Just curious, is it considered good programming practice to add some
>
code to an accessor that tells an object to update itself, for
>
instance:
>
>
-(void)setMyValue:(float)aValue
>
{
>
myValue = aValue
>
>
[self recalculate];
>
}
>
>
>
If not, would this be an alternative:
>
>
...
>
[myObject setMyValue:1.23456];
>
[myObject recalculate];
>
...
>
>
>
thanks,
>
>
- Koen.
_______________________________________________
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.