Inheritance Considered Harmful
Bill Frantz
frantz@communities.com
Fri, 23 Oct 1998 12:21:45 -0700
At 02:53 PM 10/23/98 -0400, Tyler Close wrote:
>If you pass an object to a method that expects its arguments to have a
>toString() method, then you just make sure that it's got one. If you never
>intend to pass the object to such a method, then you don't need this method.
That is true, however even in KeyKOS where there is no inheritance, there
is a convention that every object replied to a "alleged key type" call,
which roughly corresponds to getClass and toString, except the object could
lie about its type. (It could also change its type if it went thru a major
behavior change as part of its life span. The factory is an example of
such an object.)
>>On the other hand, yesterday I worked around a bug in Java's
>>PipedInputStream by subclassing. The workaround allows us to ship a
>>working program within our "ship only unmodified Java" license.
>
>The no-inheritance solution to this is to create a class that implements
>the InputStream interface by delegating the non-buggy calls to a
>PipedInputStream object.
In this case, the fix required access to "protected" i.e. accessible to
subclasses variables. In the system we are discussing, I think the only
solution would be to fix the bug in the Java class, or reimplement the
functionality in a non-javaDot class.
Note: I'm not recommending fixing bugs this way. I'm just trying to dredge
up everything nice I can say about inheritance so we don't throw out the
baby with the bath water.