Xref: utzoo comp.lang.c++:6431 comp.object:920 Path: utzoo!attcan!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.lang.c++,comp.object Subject: Re: Inheritance vs. Composition Message-ID: Date: 12 Feb 90 18:03:59 GMT References: <10465@alice.UUCP> Sender: davidm@cimshop.UUCP Organization: Consilium Inc., Mountain View, California. Lines: 35 In-reply-to: ark@alice.UUCP's message of 11 Feb 90 16:38:25 GMT In article <10465@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: In article , [I] wrote: > I'm curious as to the reasons that one might use inheritance (derivation > of a new object from the definition of an old object) and the reasons > that one might use composition (wrapping multiple objects in another > object). > The key difference in C++ is that if class D inherits [publicly] from class B, then you can pass a D argument to any function that takes a B parameter. Another way of looking at it is that if you derive D from B, then a D object does [at least] everything a B object does. If you define a class D with a B member, then you must define every operation you want a D to be able to perform, even if that is replicating many of the B operations. This is interesting... The tone here suggests that one idea is good and the other is not so good (intentional?). Also, except for "derive...[when] object does everything [the base] object does", there's no real suggestion of a model to follow here. Its more of rules of thumb about programming style. This is one of the points that I seem to be finding in the use of C++ (and perhaps generally in OOP) by programmers with a light background in the concepts (I'm certainly NOT suggesting that Andrew Koenig has a light background in the concepts). Instead of a design model to follow, the approach seems to be more of "do what seems right programmatically" and the design will take care of itself. Is this appropriate or do people see the need for more "principles" to follow to promote properly designed, reusable code development? -- =================================================================== David Masterson Consilium, Inc. uunet!cimshop!davidm Mt. View, CA 94043 =================================================================== "If someone thinks they know what I said, then I didn't say it!"