[Newbies] Is it generally considered better practice for an object to access its own variables via its getter methods?

Randal L. Schwartz merlyn at stonehenge.com
Wed Aug 6 20:51:53 UTC 2008

>>>>> "Andy" == Andy Burnett <andy.burnett at knowinnovation.com> writes:

Andy> I noticed that the Seaside tutorial has code such as:
Andy> html div class: 'menu';  with: self menuComponent.

Andy> Whereas the Scriptaculous demo code does things like this:

Andy> html paragraph id: 'position'; with: position.

Andy> I.e. they didn't bother adding (or using) a getter for position.  Who is
Andy> right, or doesn't it matter, or is there another reason why it would be
Andy> written differently?

Clearly, position is an instance var, or perhaps a temporary.  An instance var
may or may not have accessors, depending on whether it is meant to be tweaked
from the outside.  #menuComponent, on the other hand, may be just an accessor,
or it may be a whole pile of code to generate that menu on the fly.  At this
point, it doesn't matter.

Whether internal accesses to instance vars should use accessors instead of
direct access is a subject to debate (read: religious war).  I hope you
haven't accidentally triggered that thread here.  I tend to do the simplest
thing that works, and leave it at that.

Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

More information about the Beginners mailing list