Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!milano!moth.sw.mcc.com!rcp From: rcp@moth.sw.mcc.com (Rob Pettengill) Newsgroups: comp.lang.c++ Subject: Re: class design [WAS: Calling Parent functions in Child] Message-ID: <3026@moth.sw.mcc.com> Date: 29 May 91 18:42:42 GMT References: <91132.113932ACPS2924@Ryerson.Ca> <1991May15.044458.21518@minyos.xx.rmit.oz.au> <3022@moth.sw.mcc.com> <1991May24.052212.27585@alias.com> Reply-To: rcp@moth.sw.mcc.com (Rob Pettengill) Organization: MCC, Austin, Texas Lines: 70 In article <1991May24.052212.27585@alias.com> rae@alias.com (Reid Ellis) writes: ;[ My apologies if this is seen twice -- I had some problems with our ; news server recently ] ; ;Bossman writes: ;|To call A's version of isEqual, you need to use scope resolution. You ;|can do this as follows: ;| ;|B::isEqual() ;|{ ;| return (... && A::isEqual() ); ;|} ; ;Rob Pettengill writes: ;|This technique does not work for "mixin" style classes with multiple ;|inheritance. [...] mixins that seek to augment existing member ;|functions run into the following difficulty. ;| ;|For an over simplified example - one might want to write a ;|MetricWeightMixin that could be added to any class that returned an ;|English Weight. ;| ;|class MetricWeightMixin : { ;|public: ;| virtual float weight(); ;|} ;| ;|MetricWeightMixin::weight() ;|{ ;| return lbsToKilos( DontKnowWhatClassToPutHere::weight()); ;|} ; ;The problem is that you are going about solving this problem the wrong ;way. What you would want in this situation is to build classes ;representing the units involved and include copy constructors as ;appropriate. e.g.: ;.... ; ;-- ;Reid Ellis ;rae@utcs.toronto.edu || rae@alias.com ;CDA0610@applelink.apple.com || +1 416 362 9181 [work] The point of my trivial example was NOT that there was no way to solve this problem in C++. Of course C++ offers a number of ways to solve any given problem - especially when you have the freedom to redesign the class library for each problem. However, other object oriented languages have over many years developed techniques such as mixins that are powerful means of modifying and extending existing libraries of classes. Unfortunately because of limitations like this one, C++ class libraries may prove much closer to standard C libraries in their reusability and extensibility properties than to the Smalltalk and Lisp class libraries. ;rob P.S. C++ is a much more complicated language than C (more ways to make errors, more time to compile, harder to debug). My experience so far has been that C++ offers very little in the way of object oriented expressiveness to justify its cost/complexity. For the little that it does for me, I would just as soon manage my own structs and function tables. -- Robert C. Pettengill, MCC Software Technology Program P. O. Box 200195, Austin, Texas 78720, +1 512 338-3533 INTERNET: rcp@mcc.com UUCP: ..!cs.utexas.edu!milano!rcp