[Zope3-dev] "most specific" interface?

Jean-Marc Orliaguet jmo at ita.chalmers.se
Mon Sep 12 18:19:43 EDT 2005



Hi!

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()

with:

class someObject(object):
    implements(IMainInterface, ISecondaryInterface, ...)
    def interface():
        """Return the most specific interface implemented by the element."""
        return list(providedBy(self))[0]

to be able in that case to get access to the first interface implemented
by an object, as a sort of main object type.

the zope/app/component/registration.txt documentation mentions:

"""
We can now write another `IComponentRegistration` implementation that knows
about the interface; in fact, it will pick the most specific one of the
component:

  >>> from zope.interface import providedBy
  >>> class SomethingRegistration(Registration):
  ...
  ...     def interface(self):
  ...         return list(providedBy(self._component))[0]
  ...     interface = property(interface)

"""

but I haven't seen it used anywhere else. Is it safe to use this?

regards /JM


More information about the Zope3-dev mailing list