Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!sakkinen From: sakkinen@tukki.jyu.fi (Markku Sakkinen) Newsgroups: comp.object Subject: Re: Inheritance Question Message-ID: <1991Mar8.064345.6404@tukki.jyu.fi> Date: 8 Mar 91 06:43:45 GMT References: <13349@ccncsu.ColoState.EDU> Reply-To: sakkinen@jytko.jyu.fi (Markku Sakkinen) Organization: University of Jyvaskyla, Finland Lines: 61 In article <13349@ccncsu.ColoState.EDU> sharif@lamar.colostate.edu (Thomas Abdallah) writes: >I have a question regarding inheritance. > >In all my readings I have not found a decisive answer to the question can >objects inherit an attribute through more than one channel? > >Say that I have the following construct: > > Water > +-----------------------+ | | +----------------+ > | +----------+ +--+ | > v v v v > Ocean Lake Beer <--------- Hops > > >Base class WATER has an attribute, say w' which is inherited by Derived classes >OCEAN, LAKE, and BEER, and HOPS. Now BEER also inherits the attribute w' from >HOPS. Is this a legal OO construct? If not, why not? Several people have already answered, most of them pointing out that the inheritance relations are not very sensible if the names of these classes are to be taken literally. It is indeed very common that one confuses an inheritance hierarchy (is kind of) with a part hierarchy (is part of). I'll omit this part of the problem and continue the discussion without reference to the supposed real-world semantics of these classes. In principle, if Beer is a subclass of Hops which is a subclass of Water, then Beer is also a subclass of Water; thus there is no idea in declaring Beer also an immediate subclass of Water. However, I see you are using C++ terminology -- in C++ Hops may inherit Water privately and this kind of hierarchy could then be sensible; but in that case Hops is not regarded as a _subtype_ of Water. A certainly sensible and interesting situation occurs if you have a "fork-join" kind of hierarchy, the simplest possible being A / \ B C \ / D I dislike the way this is handled in Bertrand Meyer's "Object-oriented Software Construction" (a book that I hold in high esteem in general). I agree better, but not completely, with Jorgen Lindskov Knudsen's paper in the ECOOP'88 proceedings. While writing my own paper "Disciplined inheritance" for ECOOP'89, I totally agreed with the way that the multiple-inheritance addition to C++ (a language that I do _not_ hold in high esteem in general) was designed. More recently I have found that there is at least one clear problem even in the C++ approach. Essentially, the "virtuality" of a base class can be "too strong" (too global) in more complex situations where some of the derivations are private. Markku Sakkinen Department of Computer Science and Information Systems University of Jyvaskyla (a's with umlauts) PL 35 SF-40351 Jyvaskyla (umlauts again) Finland SAKKINEN@FINJYU.bitnet (alternative network address)