Class design: accessing "private" members

Alex Martelli alex at magenta.com
Mon Jul 3 05:16:29 EDT 2000


Steven D. Arnold <stevena at neosynapse.net> wrote in message
news:4.3.1.2.20000630145109.0201d9e0 at phear.dementian.com...
> At 02:15 PM 6/30/2000 +0200, Jerome Quelin wrote:
>
> >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.
>
> If you always use accessors, then you can store or derive the value in any
> way you wish internally in your class.  You may completely change the way
> the value is obtained, and the class user doesn't need to change anything

These are excellent arguments for always using accessors from OUTSIDE the
class.  Jerome, however, was talking about using them from INSIDE the class
as well, which is a different issue.


Alex







More information about the Python-list mailing list