What do you call a class not intended to be instantiated
steven at REMOVE.THIS.cybersource.com.au
Mon Sep 22 11:07:43 CEST 2008
On Mon, 22 Sep 2008 10:12:38 +1000, James Mills wrote:
> On Mon, Sep 22, 2008 at 9:39 AM, Calvin Spealman <ironfroggy at gmail.com>
>> 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
But that's precisely what I want to avoid: I don't want the objects to
share *any* state, not even their class. I'm not trying for a Borg or
Singleton: the user can call the factory as many times as they want, but
the objects returned shouldn't share any state. I don't know if what I
want has a name. Judging from people's reactions, I'd say probably not.
(For the pedantic: the "instances" will all have the same methods, but
I'm not including methods as state.)
> 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:
> class Foo(object):
> def __init__(self, env, *args, **kwargs):
> self.env = env
> def foo(self):
> if self.env.some_state:
> print "Do something useful"
Seems wasteful to me. Why give every instance it's own instance-level
reference to the shared object? Why not make env a class attribute, set
once, instead of every time you instantiate the class?
env = env
But in any case, this is not the behaviour I want. It's the opposite of
the behaviour I want. I don't want the objects to share state. I'm not
exactly sure what I said that has given so many people the impression
that I do.
More information about the Python-list