home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.object:2972 comp.lang.c++:11339
- Path: sparky!uunet!igor!thor!rmartin
- From: rmartin@thor.Rational.COM (Bob Martin)
- Newsgroups: comp.object,comp.lang.c++
- Subject: Re: Multiple Inheritance: `mix-in' classes and derived types
- Message-ID: <rmartin.711831656@thor>
- Date: 22 Jul 92 19:00:56 GMT
- References: <1992Jul21.030023.4220@csis.dit.csiro.au>
- Sender: news@Rational.COM
- Followup-To: comp.object
- Lines: 41
-
- oscar@csis.dit.csiro.au (Oscar Bosman) writes:
-
-
- |I have a design based upon some abstract classes (A, B, C, D, ... in the
- |diagram below) which I would like to mix and match to make my concrete
- |classes (L, M, N in the diagram). So far this a standard 'mix-in'
- |design.
-
- | A B C D E ...
- | |\ /| /|
- | | \/ | / |
- | | /\ | / |
- | |/ \|/ |
- | L M N ...
-
- |The problem occurs when I wish declare a function which operates on
- |all classes derived from both `A' and `C'. Ideally I'd like to say
- |something like (in modified C++ syntax):
-
- | foo(A & C my_obj) { ... }
-
- |where `&' indicates a kind of intersection of types. I can see two
- |ways to do fudge this, neither of which I like.
-
- Since A and C have no common base, what basis would foo have to deal
- with my_obj? How would it know which one it was?
-
- I think you are looking for a form of multiple dispatch, where the
- function called depends upon the type of the argument. But C++ does
- not have dynamic multiple dispatch.
-
- You could do it statically, by declaring two functions foo(A) and
- foo(B)...
-
-
-
- --
- +---Robert C. Martin---+-RRR---CCC-M-----M-| R.C.M. Consulting |
- | rmartin@rational.com |-R--R-C----M-M-M-M-| C++/C/Unix Engineering |
- | (Uncle Bob.) |-RRR--C----M--M--M-| OOA/OOD/OOP Training |
- +----------------------+-R--R--CCC-M-----M-| Product Design & Devel. |
-