[Zope3-Users] Interface confusion (still)

Markus Kemmerling markus.kemmerling at meduniwien.ac.at
Tue Jul 15 15:39:03 EDT 2008


Am 15.07.2008 um 20:53 schrieb Tim Cook:

> If interface B inherits from interface A and class B implements
> interface B; do I need to explicitly state that class B provides
> interface A?

An instance of a class provides not only the interface the class  
declares to implement, but also all base interfaces of this  
interface. In particular an instance that povides any interface, will  
always provide 'Interface'.

> Concrete example:
>
> class IElement(Interface):
>      value = Object(
>         schema=IDataValue,
>         title=_(u"value"),
>         description=_(u"""Data value of this leaf."""),
>         required=False
>     )
>
> class IDvText(IDataValue):
>
> ...
>
>
> class DvText(DataValue):
>
> ....
>
> implements(IDvText)
> classProvides(IDvText)

The last line doesn't make any sense here.  As I tried to explain  
before, if a class declares to 'implement' an interface, all of it's  
instances will provide it, whereby 'classProvides' declares the  
*class itself* to directly provide the interface.

Note: classes *implement* interfaces, their instances *provide* them.

> Will Element.value allow instances of DvText or do I need to change  
> the
> DvText classProvides call to:
>
> classProvides(IDataValue,IDvText)

You probably don't want to use 'classProvides' at all.  The  
'implements(IDvText)'  statement is enough for all instances of  
'DvText' to provide 'IDataValue'.

Regards,
Markus Kemmerling


More information about the Zope3-users mailing list