Unpythonic? Impossible??
Erik Max Francis
max at alcyone.com
Sun Mar 19 18:31:51 EST 2006
Paul Rubin wrote:
> I remember having a similar problem involving multiple base classes
> and deciding that factory functions couldn't do quite what I wanted.
> Here's a thread about it, with a recipe using metaclasses by Roeland
> Rengelink:
>
> http://tinyurl.com/rz6ne
>
> Unfortunately, the subtleties of what I was trying to do now escape
> me.
Your objection seemed to be that you'd prefer that you not have to have
an explicit if/elif... (or lookup table) since that didn't seem very OO.
Any solution that accomplishes this, whether it's a factory function,
metaclasses, or a more traditional type of "virtual constructor" (your
proposal at the end of your post, which is likely how you'd do it in
C++) all need this.
The short version of all this is all these approaches will work, are
Functionally equivalent from the user's perspective, and all require
upkeep, but some require more upkeep than others. In a dynamic language
like Python, the best solution is the most straightforward one that
requires the least upkeep. And that's a factory pattern.
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Man is a hating rather than a loving animal.
-- Rebecca West
More information about the Python-list
mailing list