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
_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to