On Tue, Apr 08, 2008 at 09:36:21PM +0200, Marco Von Ballmoos wrote:
> On Apr 7, 2008, at 09:28, Yossi Kreinin wrote:
> >I think that the only reasonable test for "is Y a subclass of X?"  
> >is "can I substitute Y objects whenever X objects are used?".  
> I agree with the test of "can I substitute Y objects whenever X  
> objects are used?"

I don't.

Subclasses can, as well as adding methods, over-ride methods in
incompatible ways.

Consider this:

  a GothMusic is-a ModernMusic is-a Music
  
Music defines a few methods, including getmood() which throws an
exception if you haven't already setmood().  ModernMusic defines a few
extra methods to do with electrickery and amplification, but inherits
Music's getmood() and setmood() unchanged.

GothMusic inherits from ModernMusic (it needs all the electrickery and
amplification) and also supplies its own version of getmood (which
always returns "suicidal") and setmood (which throws an exception unless
you tell it to be suicidal).

GothMusic and ModernMusic are not interchangeable.

-- 
David Cantrell | Hero of the Information Age

    If I could read only one thing it would be the future, in the
    entrails of the bastard denying me access to anything else.

Reply via email to