[Zope] ZClasses, inheritance & other stuff.

Sam Gendler sgendler@teknolojix.com
Wed, 08 Dec 1999 20:39:12 -0800


I ran into some similar problems last week, and I haven't had a lot of time to
pursue the issues raised, but here is what I learned.

Only classes that appear in the first level of a product in the Zope product
list are available in fiture lists of products.  Therefore, if you want to have
an heirarchy like:

Product = Software
    ZClass = Application
        ZClass = Control-Panel

You will only be able to see Applications in the list of classes to subclass.
It will be impossible to make a ZClass that inherits from Control-Panel.  This
kind of sucks, but there is something of a workaround that I found.

I hacked up the python code that makes up the ZDiscussions base classes.  This
allows me to make base classes that can inherit all kinds of nifty things from
each other, but then I just have my ZClasses inherit from these classes.  You
still wont see your ZClasses in the selection lists, but at list your 'base'
classes will be there.  It is all rather complicated and unsatisfactory, but it
does the job until zope has some more time to mature.  Just grab the
ZDiscussions classes product and hack away from there.  It works nicely in 2.0.1
and 2.1.0 on my 'Linux mandrakish  kernel 2.2.13 with lots of modifications
development box'.

Also, you won't be able to see your second level ZClasses in the list of objects
to add to a folderish class.  Assuming that you have a folderish Application
ZClass, the Control-Panel ZClass will not appear in the list of objects you can
add to the folder.  It also does not appear in the list of objects you can allow
to be added in the ZClass creation interface.  This is slightly odd, since the
stated reason behind allowing ZClasses to contain ZClasses was to prevent
objects from being instantiated outside of their context.  However, if you have
Control-Panel in the same level of the Heirarchy, but have it based on a python
base class that inherits from the classes you are interested in, you will be
able to add it to Application objects.  Confused yet?  I was.  ZDiscussions
shows how you can add an object from dtml code when it isn't available from the
pulldown of available items.

Enjoy.

If there are inaccuracies in the above, please correct them.  I didn't check my
statements.  I just typed what I remember from my own investigation of a week
ago.

--sam

Alexander Limi wrote:

> Zopistas,
>
> After fooling around a bit (a rather big bit, I might add (possibly even a
> byte)), I have come across something not mentioned in the docs. (Surprise!)
>
> My starting point is this:
>
> I want to create a superclass, which has the properties inherited by all
> the subclasses, like this:
>
> Software
>    |
>    |--Application
>    |
>    |--Game
>
> All software has properties that can (and should) be superclassed, like
> software_title, software_publisher etc.
>
> I tried to create ZClasses within ZClasses, but when I instantiate an
> object of the type Game, I can only edit the variables set specifically in
> Game, not the properties that should be inherited from Software.
>
> I want to superclass as many variables as possible, to avoid duplication of
> work. Most of the subclasses have 2 or 3 unique variables, all others are
> common.
>
> I am familiar with common OO parlance, but Zope is weird in some ways. I
> suppose the properties are inherited in the above example, but I want to be
> able to override the values from Software with instance
> variables/properties/whatever. And to edit them (the inherited properties)
> from the built-in zope manage form.
>
> How do I do this?
>
> Additionally, is there a way to automagically generate an addForm method
> AFTER editing the propertysheet for that class, to reflect the new
> variables (I'm getting tired of updating the HTML by hand every time :)
>
> Regards,
>
> Alexander.
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
>           No cross posts or HTML encoding!
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )