Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!swrinde!cs.utexas.edu!news.ti.com!ticipa!clw
From: clw@ticipa.pac.sc.ti.com (Chris Winemiller)
Subject: Re: methods, instance vars and what not...
Message-ID: <1995Feb28.161347.5655@ticipa.pac.sc.ti.com>
Organization: None
References: <3ib3p9$9a0@news.hboc.com>
Date: Tue, 28 Feb 1995 16:13:47 GMT
Lines: 31

In article <3ib3p9$9a0@news.hboc.com> niranjan.perera@hboc.com (Niranjan Perera) writes:
>Hi:
>
>Is it good practice to always have a set,and get method to access the
>instance vars you have in your object ? Or is there a fine line ? If so
>what is it ? ( questions, questions, questions... )

IMO: You should definitely have get/set methods that you think are a
proper part of your object's public interface.  (Note that, to me, such
methods may or may not simply set/get an instVar's value; it could be
more complex, and "calling" objects should never know what the
underlying implementation is.)

I typically use get/set methods always, but most of these methods should
be considered either private (i.e. not part of the public interface
available to other classes to call) or protected (i.e. not public to
"using" classes but public to subclasses---i.e. they are "hooks" for
subclasses to use and/or override).  There is always the issue of
performance (using the method rather than direct access to an instVar),
but I suspect most of the time the greater performance improvement can
be gleaned from activities other than the use of get/set methods.

P.S. "get" methods are also very nice to tranparently permit lazy
initialization, which another poster already discussed.

Regards,
Chris
==============================================================
Chris Winemiller               Internet: clw@works.ti.com
Disclaimer: I do not speak for TI.
==============================================================
