Is this a case for metaclasses?

Michele Simionato michele.simionato at gmail.com
Thu Aug 5 16:43:23 CEST 2004


Hartmut Goebel <h.goebel at goebel-consult.de> wrote in message news:<411207dd$0$7323$9b4e6d93 at newsread2.arcor-online.net>...
> Hi,
> 
> I'm currently implementing a tool for auto-generating webforms from a 
> desription file. The output should become a php-script, an asp-script, 
> zope-formulator or such. Each if it may (or may not) have javascript 
> additions. The output format should be defined ar runtime (php, 
> php+javascrip, asp, asp+javascript, etc.).
> 
> Currently I have a fixed class hierarchy:
> 
>    generic    : implements generic html widgets (input, radiobuttons)
>    php        : "mixin" for adding php-specifi code to the widget,
>                 eg. getting values from HTTP_POST_VARS/_POST
>    javascript : adds javascript scripts, eg. error checking
> 
> Obviously this does not scale as soon as I add more mid-layers (asp, 
> psp, etc.).
> 
> For me this sounds like I could benefit from using metaclasses here. 
> Before I start implementing such a beast, I want to be shure, there will 
> be a benefit.
> 
> Any suggestions?

Metaclasses are essentially syntactic sugar. You can do more or less
everything without them. For instance you can use a poor man function
to
format your classes as you wish. Then, you have to apply the function
to the every subclass by hand. If you use a metaclass, subclasses are
automatically reformatted, instead. So, using a function means
a bit more typing but greater expliciteness. Metaclasses are okay
if you want to hide to your users the fact that something magic is 
going on.


                     Michele Simionato



More information about the Python-list mailing list