In python I have getters and setters, and calculate utilities. The getters return the property, the setters set the property and the calculate utilities are functions that calculate stuff with the arguments. E.g.
obj.property = calculate_property(arguments)
However, there are various ways to implement calculate_property
, it could
- be a part of the class
calculate_property(self)
and return_property
- It could be an independent function which could be moved to a separate file
- It could be a static method
My problem with 1) is that the arguments to calculate_property can be obscured because they might be contained within the object itself, and it is not possible to use the function outside of the object. In both 2 and 3 the functional form of calculate
is retained but the namespaces are different.
So I'm ruling out 1) for this reason.
IIf I go with 2) the advantage is that I can split all my utilities up into small files e.g. utilities_a.py, utilities_b.py and import them as modules.
If I go with 3) the functions remain in the same file making it overall longer, but the functions are encapsulated better.
Which is preferred between 2) and 3)? Or am I missing a different solution?