Does a Zope Component Architecture component need to state the interfaces it implements?

174 views Asked by At

Note: I am new to ZCA, so the code may be incorrect; however, I am somewhat familiar with the way ZCA works.

Given for example:

class I1(Interface):
    def c1():
        pass

class U1(object):
    implements(I1) #is this necessary?
    def c1():
        #do some things here

Is the implements(I1) line needed, or can ZCA figure out on its own that U1 implements I1 (kind of like the way interfaces in Go work)?

1

There are 1 answers

0
Lennart Regebro On BEST ANSWER

The component does not need to state it. The interface for a component is mostly important when it is registered in the component registry, as the component lookup is done on the interfaces.

You can tell the component registry which interface a component implements in several ways. One way, the most common one, is to use the implements() call on the component itself. You can also tell the component registry which interfaces it implements when registering the component.

There are also functions for checking if a component implements a specific interface, mostly used in tests.

So yes, interfaces in ZCA works much as how they do in Go, but with the addition of a component registry (unless Go has that to but I missed it, I'm not a Go expert) where you can quickly look up components based on interfaces and names.