Path: utzoo!attcan!uunet!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!uflorida!unf7!hite386!steve From: steve@hite386.UUCP (Steve Hite) Newsgroups: comp.sys.mac.programmer Subject: Re: Multiple Inheritance for HandleObjects in C++ Message-ID: <37@hite386.UUCP> Date: 2 Jul 90 04:22:24 GMT References: <15132@reed.UUCP> <268BA8DC.4CD4@intercon.com> Organization: CS Grad Student @ Univ. of N. Florida Lines: 80 amanda@mermaid.intercon.com (Amanda Walker) writes: >In article <15132@reed.UUCP>, bowman@reed.UUCP (Eric Bowman) writes: >> I've just discovered, to my horror, that you can't create HandleObjects >> with multiple base classes in MPW C++. Are there any work arounds for this? >> Anyone know why this is the case? >The only workaround I know of is to put a HandleObject into an instance >variable of a "conventional" C++ object, with method wrappers to connect >the two inheritance chains. This is kind of grody, and it still doesn't >let you inherit from, say, several MacApp classes, but it's better than >nothing... >-- >Amanda Walker >InterCon Systems Corporation >-- Larry Rosenstein writes: >One workaround is to inherit from a primary class, and delegate some >functions to to instances of the secondary classes. In other words, instead >of inheriting from A & B, you inherit only from A, and keep an instance of B >around. Methods that need to access B's functionality do so by sending a >message to the instance of B. Eric, Amanda and Larry were kind enough to post a response to the same question I had a couple of months ago. The difference in the replies to you suggest to me that they have come up with workarounds to the problem since their discussion with me (or they already knew and forgot to mention them :-)). I bow to their experience with MacIntosh programming and I would like to suggest some additions to these. I suggest you read T.A. Cargill's article in the 1990 Usenix C++ Conference Proceedings entitled "Does C++ Really Need Multiple Inheritance?" starting on page 315. T.A. Cargill's conclusion paragraph states: "In the majority of published examples, multiple inheritance in C++ is not required to express programs. In most cases a single inheritance solution is simpler - inheritance from a class being replaced by the embedding of an object. In light of this we should view multiple inheritance in C++ as a large scale research project, in which we must evaluate its usefulness and weigh it's costs. The results to date suggest that multiple inheritance is not paying its way." Also, Grady Booch states in "Object Oriented Design w/Applications" on pp 110-111: The Meaning of Multiple Inheritance Relationships Among Classes "...The need for multiple inheritance in object oriented programming languages is still a topic of great debate. In our experience, we find multiple in- heritance to be like a parachute: you don't always need it, but when you do, you're really happy to have it on hand..." I believe Larry and T.A. Cargill are saying the same thing. Amanda is losing me at the point "...method wrappers to connect the two inheritance chains". I would need to see an example of this because I'm shooting blanks trying to visualize it. From what I've read, I don't consider their approach (Larry and T.A.) a "kluge" to get around a machine-dependent feature such as HandleObject. Rather, it's a different way of looking at the problem from a design standpoint. If you still believe that you have relationships that *must* be implemented with MI then I would answer that there is not a well thought-out way yet of programming this in C++ on the MacIntosh without fragmenting the heap. Definitely get Grady Booch's new book I just mentioned and the three C++ Usenix volumes that are a very good reference for exploratory experiences and findings in C++ implementations. ------------------------------------- Steve Hite ...gatech!uflorida!unf7!hite386!steve