[Zope3-dev] Allowing views to be registered for classes rather than interfaces.

Martijn Faassen faassen@vet.uu.nl
Fri, 18 Jul 2003 18:42:27 +0200


Steve Alexander wrote:
[why not views for classes instead? what advantages does nonceInterface have?]
> Only that you can migrate slowly to using schema by specifying just the 
> fields you require.

I think there's also something in the purity of the design; we don't
need to mess around with a lot of possibly complicated machinery
involving lookup registries and the like if we introduce just an interface.
We also avoid the confusion that may occur when we say "interfaces can
be to classes, to interfaces" and you get "what's the difference? why should I
ever use interfaces?". Also using nonceInterface is more explicit; the
class actually says it can used that way. If you can create views to
classes everywhere this could get harder to track down.

I've been thinking about evolving code..

Migration path from nonceInterface to independent interface to interface
in interface hierarchy:

  * start out with a class with a nonceInterface

  * the class is starting to get more than one client (or you want
    to encourage this). An explicit interface becomes important.
    Each step following should still result in a running system,
    so is nicely evolutionary:

    - create explicit interface in interfaces.py (near the implementation
      as it's not yet multi-implementation).

    - make class implement this interface as well; add import.
 
    - adjust zcml so views etc now depend on the explicit interface.

    - remove nonceInterface from class. Nothing should now break.

  * now it turns out we see often that there are multiple implementations
    of this interface, so we want to move it out into the separate
    hierarchy.

    - create new interface in multiple implementation hierarchy

    - make class implement this new interface as well; add import

    - adjust zcml so views etc now depend on the multi interface.

    - remove original interface from class.

    - remove original interface from local interfaces.py.

Regards,

Martijn