[Zope3-dev] I've changed my mind about inheritence of interface declarations

Jim Fulton jim@zope.com
Wed, 12 Mar 2003 10:52:07 -0500


Hi,

In the past, I had a strongly held view that interface declarations
should not be inherited.  I felt that each class should say what
it implements and that nothing should be assumed if there was no
explicit statement.

The reason I held this view was that I found class inheritence to be a
useful tool for reusing implementation independent of specification.
I still feel that inheritence is useful on occasion, but I've come to
recognize the dark side of inheritence and am much less willing to use
it than I was in the past.

To me, requiring subclasses to, by default, satisfy the promises of
their base classes is a disincentive to use inheritence and is, thus, a
good thing. ;)/2

When you see a class with base classes, you'd better darn well
know what's in the base classes. You'd pretty much better read and
understand the source code of the base classes. Further, you should
appreciate the risk that base classes may change in ways that break
your class.  If the base classes declare interfaces, you are bound by
those interfaces unless you say you aren't.

(The situation with subclassing would be better if we had an explicit
way to declare subclassing contracts that spelled out the promises
made to and demanded of subclasses.)

So, in the next draft of thge interface proposal, I'll say that
classes are bound by the interfaces declared in all of there base
classes unless they say otherwise. For example, in:

   class C(A, B):
      pass

C's instances are required to implement all of the interfaces that A's
instances and B's instances implement.

Jim

-- 
Jim Fulton           mailto:jim@zope.com       Python Powered!
CTO                  (888) 344-4332            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org