What do you call a class not intended to be instantiated

Aaron "Castironpi" Brady castironpi at gmail.com
Sun Sep 21 20:44:32 EDT 2008


On Sep 21, 6:05 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> Fixing top-posting.
>
> On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:
> > On Mon, Sep 22, 2008 at 8:39 AM, 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.
>
> [...]
>
> > Hi,
>
> > Wouldn't a normal class called State
> > suffice for storing state between calls ? And ... Creating a state
> > instance ?
>
> > For example:
>
> [snip]
>
> That's a rather big example for a rather small question.
>
> Yes, a normal class would work in many cases. In this case, the class
> itself is being produced by a factory function, and it's output is an
> iterator. Having to call:
>
> cls = factory()
> instance = cls()
> result = instance()
>
> to get anything done seems excessive, even if you write it as a one-liner
> result = factory()()().
>
> I'm not wedded to the idea, there are alternatives (perhaps the factory
> should instantiate the class and return that?) but I assume others have
> used this design and have a name for it.
>
> --
> Steven

Do you want anything from it that a dictionary doesn't have, besides
the dot-member access?



More information about the Python-list mailing list