Why less emphasis on private data?
Mon Jan 8 04:21:04 CET 2007
"Paul Boddie" <paul at boddie.org.uk> writes:
> > Consider that the above three class definitions might be in separate
> > files and you see how clumsy this gets.
> What are you trying to show with the above? The principal benefit of
> using private attributes set on either the class or the instance is to
> preserve access, via self, to those attributes defined in association
> with (or within) a particular class in the inheritance hierarchy, as
> opposed to providing access to the "most overriding" definition of an
> attribute. This is demonstrated more effectively with a method on class A:
Right, the problem is if those methods start changing the "private"
variable. I should have been more explicit about that.
self.__x = 3
class B(A): pass
self.__x = 5 # clobbers private variable of earlier class named A
More information about the Python-list