[Zope] Are products the right approach?

Dylan Reinhardt zope at dylanreinhardt.com
Thu Sep 18 12:25:41 EDT 2003


On Thu, 2003-09-18 at 00:44, Carsten Gehling wrote:
> I have created two product classes called Equipment and SpareParts. As it
> might be obvious, objects of class Equipment should only be created in the
> folder Equipment, and likewise with SpareParts.

If that's what your users need... it might be easier to treat SpareParts
as a special type of Equipment.  Treat them exactly the same but give
them slightly different properties, interfaces, whatever.


> So the "class hierarchy" is pretty much like:
> 
> SimpleItem   Loggable
>    |------+-----|
>           |
>        Equipment
> 

Good.


> and the same for SparePart

Why not:

         Equipment
             |
         SparePart


> 2) Should I make it all as classes (including the Log)?

It's not 100% clear what you mean by "the log".

Information that describes the *current* status or state of your object
should *definitely* be stored in an attribute of the class. 
 
As for keeping a history of the changes, it's hard to improve on plain
old text file logging. There might be some advantage to keeping
historical info in your class... but it would depend entirely on your
requirements.

Zope saves previous versions of objects, so your objects will grow in
size quickly if they are changed often.  Keeping extensive logs in a
product that changes often may cause you to burn through disk space very
quickly.  


> 3) How do you make relations between objects in Zope? (For use in eg.
> reporting)

A couple ways.  The obvious way is to store a "foreign key" object id as
a string and use restrictedTraverse() when you need to obtain the object
the id references.

A more involved way is to store a reference to the object.  This is
quite a bit trickier, but might be worth it if you're doing this a lot.

A bigger answer is that there might still be some room for more Zopish
thinking.  It may be better, for example, to model one-to-many
relationships as a container object and its collection of sub-objects. 
In this design, relations are assumed rather than specified.
 

> 
> 4) I'm going to make a scheduled "event handler" that sends out mail
> messages based on the latest log entries. This needs to be able to find an
> object in ZODB based on the log entry - how do I make this connection?

You can call restrictedTraverse() from within a product, a Python Script
or could use it in a script that manipulates Zope from the outside.

HTH,

Dylan




More information about the Zope mailing list