Silva 1.5 developer preview: interfaces

Martijn Faassen <[email protected]>
Newsgroups gmane.comp.web.zope.silva.devel
Message-ID <[email protected]>
Hi there,

I'm writing documentation on developer changes in Silva 1.5. As probably 
already know, Silva 1.5 is the first release of Silva which will be 
using Zope 3 technologies in the Silva core, using Five. We've already 
been using Five for layout package and the like, but we're taking it a 
step further.

Here's the note I wrote on the new way interfaces work.

Zope 3 interfaces
-----------------

Silva now uses Zope 3 interfaces throughout, instead of Zope 2 interfaces.

If you use interfaces in your own code, import the `Interface` base 
class like
this::

   from zope.interface import Interface

Instead of using `__implements__`, state that your class implements
interfaces using the `implements` class annotation::

   from zope.interface import implements

   ...

   class Foo:
       implements(IFoo)

You can check whether an instance provides an interface (i.e. whether
its class implements an interface or the interface directly provides
an interface) using `providedBy` (in Zope 2 this used to be written
'isImplementedBy')::

   IFoo.providedBy(instance)

In the rare case you want to check whether a *class* implements an
interface (i.e. whether its instances will provide that instance), you
use `implementedBy` (this used to be `isImplementedByInstancesOf` in
Zope 2)::

   IFoo.implementedBy(some_class)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.