What do you call a class not intended to be instantiated
prologic at shortcircuit.net.au
Mon Sep 22 02:12:38 CEST 2008
On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <ironfroggy at gmail.com> wrote:
> I call it an obvious misuse and misunderstanding of why you'd use a class in
> the first place. Either create an instance and not make these things
> classmethods or just share the stuff in a module-level set of variables. But
> the instantiating is the best options. Your class attributes might not be
> globals, but you're still using global state and you should avoid it where
> you can.
I concur. Use a _proper_ state object that you share
amongst your other objects. For instance, in many of
my systems and applications I write, I often have
an "Environment" instance, which is a container
object that holds other objects required by parts
of the system. Every other component/object in the
system that is instantiated recievees exactly one
instnace of thie "Environment" called, "env".
Accessing shared states amongst components/objects
within the system is as simple as this:
def __init__(self, env, *args, **kwargs):
self.env = env
print "Do something useful"
env = Environment()
foo = Foo(env)
-- "Problems are solved by method"
More information about the Python-list