Class design: accessing "private" members
Jerome Quelin
jerome.quelin at insalien.org
Fri Jun 30 04:14:03 EDT 2000
Hi all,
When designing a class, I wrote some accessors (get_var() and set_var()
methods) for my "private" members (private in the sense that I don't want
somebody to access them directly from outside the class.
I was wondering if it is good practice to acceed to those private members from
_inside_ my class, or should I use the accessors methods too?
Well, ok, it would be slower (function calls are always more expensive), but
isn't it more OO-well-behaviored?
-- File test.py
class Spam:
def __init__(self, name="eggs"):
self.set_name(name) # Which is the
self._name = name # better/cleaner?
def set_name(self, name):
self._name = name
-- End of file
Thanks,
Jerome
--
jerome.quelin at insalien.org
More information about the Python-list
mailing list