swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multiple inheritance


From: Sven Thommesen
Subject: Re: multiple inheritance
Date: Wed, 13 Nov 1996 10:59:04 -0600

At 01:47 PM 11/12/96 EST, Ginger Booth wrote:
>Hi, gang,
>
>    I'm presently playing with variants of my base classes, and getting kinda
>grumpy....  Time after time, I get into situations where I want to combine
>two complexes of behaviors, like:
>
>       SpeciesCommon       ParameterizedCommon
>            |      \       /
>            v       ---v---
>  CompositeSpecies     ParameterizedSpecies
>  
>And yes, I'm used to C++. ;)  And yes, the "paste" button makes me profoundly
>uneasy.
>
>Is there a thought process I might acquire to become less aggravated at the
>lack of multiple inheritance?  Does one just stack them up and paste bandages
>over the parts that don't belong in the object under construction?  Can 
>protocols have code?
>
>Any Obj-C pointers appreciated.
>
>Thanks,
>    Ginger
>    

Ginger,

as you know there's a religious war among oo-language developers over single
vs. multiple inheritance, and Objective-C unfortunately chose to follow the
purist line on this issue. Unfortunately, because (I suspect) multiple
inheritance is more useful in simulation contexts than in most other
programming tasks.

You might want to check out the online book on Objective-C from Next,
chapter 4, sections on "Forwarding" and "Forwarding and Inheritance".
The solution (kludge) suggested for situations where you need multiple
inheritance is for a composite object to own a copy of each of the objects
that would otherwise be superclasses, and for the methods of the composite
object to forward messages to the component designed to handle them.

This should be conceptually clean, and avoid the 'cut-and-paste' source of
disasters. Only problem is messaging overhead.

Haven't tried this myself though, so if you do, be sure to report your
successes or gripes!

--Sven



reply via email to

[Prev in Thread] Current Thread [Next in Thread]