[Zope3-dev] Interface declaration API

Jeremy Hylton jeremy@zope.com
11 Mar 2003 18:14:57 -0500


On Tue, 2003-03-11 at 17:43, Phillip J. Eby wrote:
> At 04:35 PM 3/11/03 -0500, Jim Fulton wrote:
> >The way you would reject base-class interfaces is to use implements. That is,
> >if you use implements, you implement *just* what you say you implement,
> >so I still think 'doesNotImplement()' is a yagni.
> 
> This is probably a matter of design principles.  In general, I go for the 
> Liskov substitutability principle; that is, I should be able to use a 
> subclass where the superclass is acceptable.  This implies, in other words, 
> that failing to implement a superclass' interfaces is a no-no.

I think substitutability is a goal here, but in a specialized way.  You
should be able to substitute any implementation of the interface.  I
think one of the purposes of interfaces is to decouple substitutability
from inheritance.  If you want to class B to inherit from A but not be
usable as an A, then you give it a different interface.

>   In the rare 
> case where I want to reject the legacy of my ancestors, I want to 
> explicitly identify what contracts I'm rejecting, rather than try to 
> reiterate every contract I might still implicitly be supporting.  I only 
> want to use 'implements()' if I want to reject *all* ancestral contracts, 
> which is something I've never wanted to do.  For that matter, because of 
> the LSP, I'm not sure I've ever actually rejected even one ancestral 
> contract, but I can easily conceive of situations where I might want to 
> reject some subset of them.

If you are using inheritance just for implementation purposes and you
don't want to claim to implement A's interfaces, then you should
explicitly declare the interface(s) that B implements.  Otherwise, A may
later evolve in implement interface IQuam.  When B was written, A didn't
implement IQuam, so there was no need for B to say it did not implement
IQuam.

Jeremy