• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: accessor question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • RE: accessor question
      • From: Koen van der Drift <email@hidden>
References: 
 >accessor question (From: Koen van der Drift <email@hidden>)

  • Prev by Date: Finder & images
  • Next by Date: Re: NSMailDelivery
  • Previous by thread: Re: accessor question
  • Next by thread: RE: accessor question
  • Index(es):
    • Date
    • Thread