OOP allows for encapsulation of implementation details such as hiding the name of variables used to store an object state. This is associated with accessors like get_xxx() and set_xxx(value) methods.
When such accessors are present, all accesses, except in the owning class, should proceed through the accessors. Python offers a way to enforce this usage by prefixing the xxx-associated variable with two underscores __ (or one depending on context).
However this convention is not consistently observed in Gramps.
Taking the example of PrivacyBase
class, it store the privacy state into a boolean variable privacy
and defines get_privacy(self)
and set_privacy(self,value)
accessors. But these accessors are not used at all in any gramps/gen/lib/ module (which could be tolerated because all classes here derive in some way of PrivacyBase
) nor in gramps/gui/.
There are get_privacy(self)
and set_privacy(self,value)
access methods defined gramps/plugins/importer/importprogen.py and used in various locations in gramps/plugins/importer/ modules. But when referring to the privacy flag of primary objects, private
is referenced directly.
I kind of remember that in the GUI part, accessors are also defined but code use “indifferently” accessors and variable name.
What is the recommended practice?
The guidelines say nothing about it.