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

Tres Seaver tseaver@zope.com
12 Mar 2003 14:14:06 -0500


On Wed, 2003-03-12 at 12:18, Shane Hathaway wrote:
> Barry A. Warsaw wrote:
> >>>>>>"JF" == Jim Fulton <jim@zope.com> writes:
> >>>>>
> > 
> >     JF> (The situation with subclassing would be better if we had an
> >     JF> explicit way to declare subclassing contracts that spelled out
> >     JF> the promises made to and demanded of subclasses.)
> > 
> > Classes that are intended to act as base classes should be designed
> > that way, which means specifying a formal interface for its derived
> > classes.  E.g. Something like C++'s protected methods.
> 
> I think Stroustrup would think along those lines.  In C++, virtual 
> methods are safe to override, while non-virtual methods aren't 
> necessarily safe (you can do it, but you might not get what you 
> expected).  And Java has "final" methods (which you can't override). 
> Python has no way to declare anything similar.

The other important thing for this conversation is that, in C++, only
*public* inheritance implies substitutability (and therefore thLSP); 
*protected* and *private* inheritance exist only to support different
kinds of implementation reuse.  The compiler enforces this restriction,
in that non-member methods aren't allowed to pass references or pointers
to the derived class as arguments to functions whose signatures call out
reference / pointer to the base.  With *private* inheritance, even
derived class methods can't pass 'this' as a pointer-to-base.

While very few C++ programs make significant use of non-public
inheritance, Stroustroup expected it to be common:  the default is
private!

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com