[Zope] Using Zclasses

Martijn Pieters mj@antraciet.nl
Tue, 06 Jul 1999 14:40:36 +0200


At 01:57 06/07/99 , Michael Bernstein wrote:
>I've been playing around with Zclasses for awhile, but have reached a
>bit of a stumbling block.
>
>I want to create a set of Zclasses that can only be contained within
>certain other Zclasses. An arbitrary example would be a 'book' object
>that can only be created inside a 'shelf' object.

Create the 'shelf' object with ObjectManager as a base class. Now, on the 
Methods tab, create the 'book' ZClass (including the factory object, and 
the creation form and method). It now will automatically be included in the 
Add list of the shelf object.

>I also would like to add a property to a ZClass that is a pointer to an
>instance of another ZClass of a certain type. An arbitrary example would
>be a 'Book' ZClass that has an 'Author' property that points to an
>instance of an 'Author' ZClass.

You can't create a property of an arbitrary object type on ZClasses. You 
can treat the author class the same way you did with the book class, derive 
the Book class from ObjectManager, and create your author ZClass on its 
methods tab. If the author ZClass should be accessible in other places as 
well, you should create it at product level and include in the 'Subobjects' 
tab of the book class.

Note, that to the end user, your book never has to look like a folderish 
object. If you unselect the 'Objects should appear in folder lists?' option 
on the 'Subobjects' tab, your ObjectManager derived ZClass will look like 
any other simple class. However, it is now possible to contain one or more 
'author' instances in your 'book' instance.

--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------