[Zope3-Users] To Subclass, or to Adapt?
Dominik Huber
dominik.huber at perse.ch
Mon Aug 15 06:47:33 EDT 2005
James Allwyn wrote:
>>>used the following to get it to also provide
>>>this as a property:
>>>
>>>rating = property(getRating)
>>>
>>>
>>Yes, but I would not offer both. I would limit the
>>interface to the
>>property only, because the property can used more
>>easily generating
>>generic view such as schemadisplay, add/editform and
>>form...
>>
>>
> My adapter provides a method getRating. I've
>
>
>I'm interested in the theory behind whether to provide
>a method or a property from an adapter. I had
>initially used a method, because I was following the
>examples from the books (which are on the ISized
>adapter, which provides two methods). Then I noticed
>something along the lines of foo=property(getFoo) in
>Stephan's book, which seemed to turn the getFoo method
>into a foo property. Why is one better than the other?
>Stephan seems to use it particularly when he has
>getters and setters defined - in the case of my
>ratings I think they will be calculated rather than
>set, so would this lessen the relevance of the
>providing a property rather than a method?
>
>
Definitly both are right and the decision might often be a question of
personal taste, but in certain circumstances the properties are more
convenient for example:
- Reuse of interface information:
see zope.schema: Field declarations ('Interface' to a single
attribute) have a defined api.
- Getter/setter for free using field information of an interface:
See zope.schema.fieldproperty: foo= FieldProperty(IFoo['foo'])
- Use widgets to provide HTML-represantions for display and form inputs
- The form framework (zope.app.form) respects solely the schema part of
an interface to provide its generic views
- ...
So I judget your case only by convenience and suggested therefore the
properties.
Regards,
Dominik
More information about the Zope3-users
mailing list