[Zope] Class variables in ZClasses
Loren Stafford
lstafford@icompression.com
Fri, 3 Dec 1999 09:33:00 -0800
Darran,
The way I understand it, Zope's implementation of properties allows you to
use them as class constants, class variables, instance constants, or
instance variables depending on what methods you create to modify the
properties and how and when you use (or permit others to use) those methods.
- Class constants are properties that have no methods to change them (aside
from the class Property Sheets tab).
- Class variables (now that I think about it, I can't see how to implement
them).
- Instance constants are properties that are assigned values only by the
class_add constructor.
- Instance variables are properties that are assigned values by methods of
the class.
I don't understand how it's implemented in Zope, but I'd guess that all Zope
does is give the instance it's private copy of the property if and only if
the instance has modified the property, otherwise give the instance the
value of the class property.
Maybe Jim will step in again and correct or clarify.
-- Loren
> -----Original Message-----
> From: dee124@rsphy1.anu.edu.au [mailto:dee124@rsphy1.anu.edu.au]On
> Behalf Of Darran Edmundson
> Sent: Thursday, December 02, 1999 21:12
> To: zope@zope.org
> Subject: Re: [Zope] Class variables in ZClasses
>
>
>
> Jim, pardon my denseness but I'm still struggling with this.
> It seems like your response contains conflicting ideas.
>
> > You simply have to arrange to get SubjectChoices to be an
> > attribute of the class managed by the ZClasses.
>
> > import Zope
> > app=Zope.app()
> > app.Control_Panel.yourProduct.yourZClass.setClassAttr(
> > 'SubjectChoices',{...})
> > get_transaction().commit()
> > app._p_jar.close()
>
> I understand the sentence above and the code snippet to
> mean the same. Namely, that *if* MyProduct.MyZClass had
> a properties tag, I could simply use this to add a new
> property which all instances of MyZClass would acquire.
> ZClasses don't have property forms and so I use the python
> code to add the desired attribute. However, ...
>
>
> > If there
> > was a way to create dictionary properties, you could do this
> > via a propertysheet, since ZClass propertysheets create
> > default property values in classes. Since Zope doesn't
> > give you a way to spell this through the web, you have to resort
> > to Python.
>
> If I add a ClassVariables propertysheet to MyZClass, won't this
> get instantiated every time I create a new MyZClass instance?
>
> It seems to me that "class variables" cannot be added to a ZClass
> via the web interface, not just for dictionaries (since this isn't
> a recognized Zope property type), but for all property types.
>
> Cheers,
> Darran.
>
> --
> Darran Edmundson [Darran.Edmundson@anu.edu.au]