Choose: class with static methods or module with functions
somm1105 at bellsouth.net
Fri Apr 17 04:27:18 CEST 2009
On Thu, 16 Apr 2009 09:55:40 -0700, bearophileHUGS wrote:
> But there can be a situation where you want to keep functions even
> closer, for example because in a module you have two classes and two
> groups of functions related to each class. In such situation
> staticmethods seem better.
In order not to guess in the face of ambiguity, I propose that you handle
that case ("two classes and two groups of functions related to each
class") by splitting that module into two modules. One module would
contain one of the classes and its related functions; the other module
would contain the other class and its related functions.
Unless, of course, you mean that you have two groups of functions, each
of which are related to *both* classes, in which case I'd still prefer
module-level functions to staticmethods, but I'm old enough that I only
speak Object Oriented as a Second Language.
Dan Sommers A death spiral goes clock-
<http://www.tombstonezero.net/dan/> wise north of the equator.
Atoms are not things. -- Werner Heisenberg -- Dilbert's PHB
More information about the Python-list