in reply to Make your classes use their own methods

Worry only about the things that you have to implement.

  1. Sometimes inheritance simply doesn't make sense. At least at the moment. Why pay the price now if it's easy to change the code later?
  2. Again, this is quite often a fairly safe asumption.
  3. If you do not write tests for the other methods you'll never know whether the other methods AND the accessors are OK anyway.
  4. How often do you change the implementation of your objects? And do you really expect this to be an "automated" transition?
  5. You should be retrofiting your code from time to time anyway. And again how often do you go around changing naming conventions?

If your object is part of an OO hierarchy, go ahead and use accessors even inside the object, if not ... don't worry, you can change it later.

Jenda
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
   -- Rick Osborne

Edit by castaway: Closed small tag in signature

  • Comment on Re: Make your classes use their own methods

Replies are listed 'Best First'.
Re: Re: Make your classes use their own methods
by petdance (Parson) on Nov 24, 2003 at 19:43 UTC
    I certainly am not saying that you should always have accessors. What I AM saying is that if you DO have them then you should ALWAYS use them. They are no more difficult to use than direct member access.

    xoxo,
    Andy

      Well sometimes they are a bit harder to use

      $selt->{count}++; $selt->count++; # I guess that's not gonna fly. # Except maybe if you do something spicy with LHS subroutines.
      But that's not the point. They are much slower. Therefore even if you force (politely ask) the outside world to use the accessors you may not want to use them inside the class. Of course you should be aware of the consequences :-)

      Jenda
      Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
         -- Rick Osborne

      Edit by castaway: Closed small tag in signature

Re: Re: Make your classes use their own methods
by ihb (Deacon) on Nov 30, 2003 at 01:15 UTC

    What if someone decides that he wants to inherit your class, even though you didn't plan that? Personally I believe users of my module to be competent and not seldom more competent coders than I so there's a great risk I'll overlook something that at least some users will see. So I try to not paint myself into corners if I easily can avoid it. This applies to more than inheritance and accessors.

    Why pay the price now if it's easy to change the code later?

    For a user that wants to extend your module it's not easy. In an ideal world the user would send you a patch and then write his extention, but we're not quite there yet...

    One should be nice to one's users! (At least if it hardly costs you anything.)

    ihb