From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=unavailable autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.ada:5790 comp.object:3781 Newsgroups: comp.lang.ada,comp.object Path: utzoo!utgpu!cunews!knight From: knight@mrco.carleton.ca (Alan Knight) Subject: Re: Difference between inheritance and package use Message-ID: <1991Jun23.135921.19166@cunews.carleton.ca> Summary: Use both, obviously Keywords: Inheritance, Object Orientation Sender: news@cunews.carleton.ca Organization: Carleton University, Ottawa, Canada References: <1991Jun21.224640.24583@src.honeywell.com> <1991Jun22.013149.28268@netcom.COM> Date: Sun, 23 Jun 1991 13:59:21 GMT List-Id: In article <1991Jun22.013149.28268@netcom.COM> jls@netcom.COM (Jim Showalter) writes: >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