What do you call a class not intended to be instantiated

Matimus mccredie at gmail.com
Mon Sep 22 14:14:52 EDT 2008


On Sep 21, 3:39 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> I have a class which is not intended to be instantiated. Instead of using
> the class to creating an instance and then operate on it, I use the class
> directly, with classmethods. Essentially, the class is used as a function
> that keeps state from one call to the next.
>
> The problem is that I don't know what to call such a thing! "Abstract
> class" isn't right, because that implies that you should subclass the
> class and then instantiate the subclasses.
>
> What do you call such a class?
>
> --
> Steven

It actually sounds like you are doing something similar to the
monostate pattern. In Java the monostate pattern is usually
implemented by creating a class that only has static functions and
variables. You _can_ instantiate it, but every instance will share the
same state. In that way it is very similar to the Singleton pattern
(http://en.wikipedia.org/wiki/Singleton_pattern).

In Python I haven't found a need for monostate, since you can override
__new__ and return exactly the same instance. However, you you wanted
to be able to inherit a monostate object and share some of the state
between the class and subclass it might still be useful.

Perhaps if you post some example code?

Matt



More information about the Python-list mailing list