Class design: accessing "private" members

Olivier Dagenais olivierS.dagenaisP at canadaA.comM
Fri Jun 30 08:45:28 EDT 2000


I usually don't use accessors to manipulate my member variables, unless my
accessors trigger some sort of "changed" flag, so that I know my object
needs to be updated or re-persisted.

--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III


"Jerome Quelin" <jerome.quelin at insalien.org> wrote in message
news:962367319.379353174 at news.libertysurf.fr...
> "Alex Martelli" <alex at magenta.com> wrote:
> >By calling the accessors, rather than accessing the data
> >directly, you ensure that if somebody overrides the
> >accessor functions in a derived class you'll be calling
> >the derived-class versions of those functions.  If that is
> >what you want (one direction along which you want to let
> >inheritors of your class extend or tweak behaviour), then
> >it's probably worth the overhead you mention.
> The class isn't to be derived any further. It's a class that I use in an
> application, and that may be imported in some other applications, but not
to be
> inherited.
>
> Then, is it better/cleaner to access private members with accessors or
not?
> Is it a matter of style? Or are there hidden caveheats using (or not
using)
> accessors? It _seems_ cleaner to use accessors, but man, it's quite
awkward.
>
> Jerome
> --
> jerome.quelin at insalien.org





More information about the Python-list mailing list