Jean-Marc Orliaguet wrote:
> Philipp von Weitershausen wrote:
>>Jean-Marc Orliaguet wrote:
>>>is the order of the list of interfaces implemented by an object subject
>>>to internal changes?
>>>I have identified the need for such a pattern:
>>> iface = object.interface()
>>> implements(IMainInterface, ISecondaryInterface, ...)
>>> def interface():
>>> """Return the most specific interface implemented by the element."""
>>> return list(providedBy(self))
>>>to be able in that case to get access to the first interface implemented
>>>by an object, as a sort of main object type.
>>We usually do this differently. If some interfaces are special types
>>(e.g. IFile is a content type) then we have this interface provide
>>ISpecialType (e.g. IFile provides IContentType). ISpecialType is an
>>interface extending IInterface.
>>Then, no matter where in the list of provided interfaces the type is, it
>>can be fetch with queryType. Let's take the IFile example from above and
>>set it up as a content type:
>> >>> from zope.app.content.interfaces import IContentType
>> >>> from zope.app.file.interfaces import IFile
>> >>> from zope.interface import directlyProvides
>> >>> directlyProvides(IFile, IContentType)
> I see, this is clever, and it simplifies the code.
> the idea is that you define as many categories as you need: IMetaType,
> ISomeCategory, IWidgetType ... and you create relations between
> interfaces with:
> directlyProvides(IFile, IContentType)
> as if you had a relation tool, then every object that implements IFile
> (no matter in what position) will have the IFile content type?
> But where do you put the 'directlyProvides' statement?
Like Jim said, anywhere in Python code. The fact that IFile directly
provides IContentType isn't bound to any class statement.
The typical case, though, is to use ZCML, as Jim also mentioned:
See the beginning of chapter 5 (page 55) of my book for a further
explanation and an example from the interpreter shell.
Zope3-dev mailing list