comp.lang.ada
 help / color / mirror / Atom feed
From: knight@mrco.carleton.ca (Alan Knight)
Subject: Re: Difference between inheritance and package use
Date: Sun, 23 Jun 1991 13:59:21 GMT	[thread overview]
Message-ID: <1991Jun23.135921.19166@cunews.carleton.ca> (raw)
In-Reply-To: 1991Jun22.013149.28268@netcom.COM

In article <1991Jun22.013149.28268@netcom.COM> jls@netcom.COM (Jim Showalter) writes:

   <Inheritance vs. Composition stuff deleted>

>Which of these is better? Well, there certainly does seem to
>be a lot of argument about it. We know more about the first

I hardly see that these are contradictory or exclusive.  This is like
having an argument in cooking about which is better, cooking things or
mixing them together.

>people who believe strongly that the old way of doing things
>is all wrong, that the new kind of tree is far superior, and
>they'll chew your leg off at the hip if you give them any static
>about it. ;-)
>
>I have been wondering for some time if there isn't some kind of
>bifurcation in people's cognitive styles that leads them to favor
>one kind of tree over the other. I've had lots of inheritance

Careful, you're starting to use "the world can be divided into two
kinds of people" arguments.  Soon somebody will be claiming that
preference for inheritance or composition will be based on what part
of your brain you use more often.  (It's been done, in BYTE magazine,
no less.  Good for a laugh, anyway). 


>I do find them, I find a lot MORE cases where the more traditional
>tree is a considerably less artificial approach. This is what leads
>me to ask (and get a lot of flak for asking) whether the wonders of
>inheritance haven't been a wee bit oversold...
>
>For example, I look around in nature and, yes, I do find examples of
>inheritance. But I also find tractors. And there are, to the best
>of my ability to discern their presence, scant few examples of
>inheritance in tractors. What I find in tractors is subassemblies
>(big ones, such as chassis, electrical, etc--subsystems), which
>in turn are decomposed into smaller components such as differentials,

  I think that only the most rabid of leg-chewers would argue for the
exclusive use of inheritance over composition.  Inheritance is useful
for describing variations on basic concepts, usually with a lot of
interface sharing.  Composition (i.e. the traditional approach) is
good for describing sub-assemblies.
   A tractor does not share much interface with a wheel or an engine.
Describing a tractor as inheriting from Wheel and Engine, would be
stupid.  A tractor is composed of different pieces.
   A tractor wheel, on the other hand, is not all that different from
an automobile wheel or even a bicycle wheel.  Describing these in
terms of inheritance from a common base class makes good sense.  
   Both hierarchies are useful, and one normally uses both at once.
Tractors are Vehicles, a lot like cars or bicycles.  It is useful to
be able to describe a tractor as being a subclass of vehicle.  All
vehicles share a number of common components (wheels, transmission,
steering mechanism).  Tractors add extra components (baler power
shaft, diesel engine, hydraulics).  Thus a tractor both inherits and
is composed of sub-assemblies.
   All OO languages that I know support both these mechanisms. 
   Undoubtedly there are those (longing to sink their teeth into a
good femur) that have overemphasized the use of inheritance, just as
there are those who attack the need for it at every opportunity.  The
prudent programmer will seek the truth between these opposing views.
-- 
--
  Alan Knight   knight@mrco.carleton.ca  +1 613 788 5783   Support
  Dept. of Mechanical and Aeronautical Engineering         the
  Carleton University, Ottawa, Ontario, Canada, K1S 5B6    LPF

  reply	other threads:[~1991-06-23 13:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1991-06-21 22:46 Difference between inheritance and package use Mike Miller
1991-06-22  1:31 ` Jim Showalter
1991-06-23 13:59   ` Alan Knight [this message]
1991-06-23 18:51     ` Jim Showalter
1991-06-23 22:02       ` Milt Ratcliff
1991-06-23 20:16     ` Philip Machanick
1991-06-24 19:33 ` Douglas S. Gray
1991-06-24 20:39   ` Rob Spray
1991-06-25 16:04     ` Douglas S. Gray
1991-06-25 19:52   ` Jim Showalter
  -- strict thread matches above, loose matches on Subject: below --
1991-06-22  3:53 Chuck Shotton
1991-06-23  3:06 ` Jim Showalter
1991-06-23  8:38   ` Orville R. Weyrich
1991-06-24  3:32   ` Marco S Hyman
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox