From: johnson@cs.uiuc.edu (Ralph Johnson)
Newsgroups: comp.lang.ada,comp.object
Subject: Re: OOD, Ada, and Inheritance
Date: 9 Nov 92 18:56:16 GMT
Article-I.D.: cs.BxGpxt.FDw
Organization: University of Illinois, Dept. of Comp. Sci., Urbana, IL

weide@elephant.cis.ohio-state.edu (Bruce Weide) writes:

>The questions about inheritance in Ada, and especially the responses
>about inheritance being "simulated" in Ada, are interesting.  Those
>who are REALLY interested in this issue would do well to consider
>whether inheritance (as commonly practiced in OO languages) is
>something you ought to want; see the paper by J.P. Rosen in the Nov
>1992 issue of Comm of the ACM.

I have read Rosen's paper several times, and I dislike it more
every time I read it.  The fact that inheritance *can* be misused is 
no argument against it.  Rosen was putting up a straw man -- people 
in the C++ and Smalltalk community place great value in components and
do *not* believe that inheritance is the only, or even the primary,
way to reuse software.  I suppose you could get that opinion from
reading papers, since a lot of papers on software reuse from an OO 
point of view are a bit one-sided and don't give a complete picture,
but you can't get that opinion if you look at the kind of systems
that are built.  For example, the GNU C++ classes rely almost
entirely on reuse by composition.  This is one of its weaknesses,
in my opinion, because the best reusable frameworks will carefully
trade off the extensibility and higher coupling of inheritance with
the ease of use and run-time flexibility of composition, but it
certainly shows that people in the C++ community value composition.
InterViews or the latest version of Model/View/Controller from ParcPlace
ARE very good examples of how to combine inheritance and composition to
make something that is much more powerful and easy to use than either
technique could provide on its own.

Just as serious a problem with Rosen's paper is the opinion that
polymorphism is optional and can be done by hand when needed.  We
could say the same thing about control structures, of course.  In
practice, lack of language support for polymorphism will mean that
people will not use it for little things, and will consider using
it to be difficult and a technique to be used only for hard problems.
In contrast, in C++ or Smalltalk polymorphism is so easy to use that
it is almost bad design to ever use a case statement, and so programs
are easier to extend.  Rosen seemed to contradict himself when he
talked about why Ada 9X wanted to add support for polymorphism, so
perhaps he doesn't really believe this, but was just trying to explain
why Ada was designed the way it was.  Ada is 14 years old, so trying
to justify it in terms of current software engineering practices seems
pointless to me.  (Note: "justify" is not "analyze" or "critique".)

I've been pretty negative about his paper.  The thing I liked about
his paper was his examples of designs that used inheritance
that would probably be better of using composition.  He is right.
There are several different ways of using inheritance, and I suppose
some of the differences are just stylistic, and there might not be
a right or wrong way, but I tend to agree with him that the examples
he gave are bad examples, and that composition is a better way to
solve those problems.  Where I disagree with him is his claim that
the entire object-oriented community, or even the majority of it,
thinks that these examples are good design.  Moreover, I disagree
that his examples showed what is important about inheritance.

After 7 years of experience in building object-oriented systems, I
think that polymorphic composition probably has a bigger impact on 
program structure than inheritance, but I wouldn't want to give up 
inheritance.  Some important design patterns that are based on inheritance 
are template methods in abstract classes (which can be simulated by 
generics in Ada), default implementation of abstract methods or overriding 
standard templates for greater efficiency (which can't be), and use of 
abstract classes to represent behavioral constraints on interfaces.  I 
want to have inheritance in my programming languages.  I am perfectly 
happy for someone to improve it or come up with new ways of doing the 
same things, but standard composition is not a replacement for inheritance, 
but is instead an addition.  (Or inheritance is an addition to composition,
since composition was first.)

Ralph Johnson -- University of Illinois at Urbana-Champaign
Xref: sparky comp.lang.ada:3218 comp.windows.x.motif:7294