Standard behaviour of a getSomething method

Batista, Facundo FBatista at uniFON.com.ar
Mon Jul 28 15:52:31 CEST 2003


#- >> Considering that this attribute is always another object 
#- (everything
#- >> is an object in Python), what should getMyAttrib do?
#- >>
#- >> 1) Return the object
#- >> 2) Return a copy of the object
#- 
#- Because returning a copy is seldom needed, I prefer returning the
#- object itself. If it's an immutable object, the difference doesn't
#- matter, anyway. If it's a mutable object, you should note the access
#- semantics in the docstring, as someone else pointed out.

Here it's the very point. I don't want to anybody to access the class
attribute from outside.

Beyond the get/set interface mechanism, if I return the object (a mutable
one), this object can be modified from outside. Shouldn't I return a copy of
the object in this case?

Thanks.

.	Facundo





More information about the Python-list mailing list