What do you call a class not intended to be instantiated
steve at REMOVE-THIS-cybersource.com.au
Mon Sep 22 01:05:15 CEST 2008
On Mon, 22 Sep 2008 08:54:43 +1000, James Mills wrote:
> On Mon, Sep 22, 2008 at 8:39 AM, Steven D'Aprano
> <steve 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.
> Wouldn't a normal class called State
> suffice for storing state between calls ? And ... Creating a state
> instance ?
> For example:
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.
More information about the Python-list