Factory pattern implementation in Python

George Sakkis george.sakkis at gmail.com
Mon Dec 4 13:11:48 EST 2006


Romulo A. Ceccon wrote:
> George Sakkis wrote:
>
> > If you actually intend to
> > 1) name your Event subclasses Evt1, Evt2, ... EvtN and not give more
> > descriptive (but unrelated to the magic event number) names
>
> No, those names are just an example. The actual classes have
> descriptive names.

Even then, I'd prefer a naming convention plus a global Event registry
than relying on inspect, both for implementation and (mostly)
documentation reasons. It's good if a human can browse through a list
of a few dozen names and immediately know that
CamelCasedNameEndingWithEvent is an Event subclass. It's also good to
be able to find in one place the explicit mapping of magic numbers to
classes rather than searching in the whole file (or worse, multiple
files) for it. YMMV.

George




More information about the Python-list mailing list