Xref: utzoo comp.lang.c++:6442 comp.object:927 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!lth.se!newsuser From: dag@control.lth.se (Dag Bruck) Newsgroups: comp.lang.c++,comp.object Subject: Re: Inheritance vs. Composition Message-ID: <1990Feb13.074423.3580@lth.se> Date: 13 Feb 90 07:44:23 GMT References: <10465@alice.UUCP> Sender: newsuser@lth.se (LTH network news server) Organization: Department of Automatic Control, Lund, Sweden Lines: 33 In article cimshop!davidm@uunet.UU.NET (David S. Masterson) writes: >In article <10465@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: > 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. > >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? In general, I think insight is more important than principles. We often talk about reuse, but we must distinguish between (at least) two different forms of reuse: reuse of code and reuse of abstraction. The "American" argument for OOP is to reuse existing code, while the "European" argument is to use inheritance as a structuring and abstraction mechanism. I find both equally important, but reuse of code is much easier than reuse of abstraction. I also believe reuse of code naturally lends itself to bottom-up development, while reuse of abstraction lends itself to top-down development. In practice we often alternate between the top-down and the bottom-up approaches. The C++ world is almost singularly concerned with code reuse. This is demonstrated whenever C++ is described, and also when Andrew Koenig uses a function call for describing inheritance. It is also obvious that many Smalltalk, Objective-C and Eiffel friends believe that reuse of abstraction is next to impossible in C++ -- a complete misconception in my view. Dag M. Bruck