Python has a "really hidden encapsulation"?

dmytro starosud d.starosud at gmail.com
Thu Oct 21 21:41:26 CEST 2010


Thanks for answer,

Attribute accessing inside the class is implemented by getters and
setters: "min_set", "min_get", "max_set" and "max_get".
You can put your logic to this functions and parameter "prop" is the
direct reference to this property.
I can create a "really read-only attribute", and other developers
which use my class can't affect this attribute, they can only using
getters and setters written inside the class.
I realize that attribute changes can be just in getters and setters,
but this restriction it's insignificant.

In case with using __setattr__: you always can access an attribute by
__dict__ and implementation of this method also use __dict__,
but in case with "hidden property" you can rich the reference to
property inside the class (it is parapeter "prop") and outside the
class you cannot.

I didn't want to affirm that this way is like C# or Java
encapsulation, but I think the fact that physical reference to
attribute hides is really interesting and is the way to do
encapsulating like in C# or similar others.

*I have been locking for encapsulating in Python because all say that
is no way to "really" hide attributes. I think I disproved this.



More information about the Python-list mailing list