home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / object / 2972 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.8 KB

  1. Xref: sparky comp.object:2972 comp.lang.c++:11339
  2. Path: sparky!uunet!igor!thor!rmartin
  3. From: rmartin@thor.Rational.COM (Bob Martin)
  4. Newsgroups: comp.object,comp.lang.c++
  5. Subject: Re: Multiple Inheritance: `mix-in' classes and derived types
  6. Message-ID: <rmartin.711831656@thor>
  7. Date: 22 Jul 92 19:00:56 GMT
  8. References: <1992Jul21.030023.4220@csis.dit.csiro.au>
  9. Sender: news@Rational.COM
  10. Followup-To: comp.object
  11. Lines: 41
  12.  
  13. oscar@csis.dit.csiro.au (Oscar Bosman) writes:
  14.  
  15.  
  16. |I have a design based upon some abstract classes (A, B, C, D, ... in the
  17. |diagram below) which I would like to mix and match to make my concrete
  18. |classes (L, M, N in the diagram).  So far this a standard 'mix-in'
  19. |design.
  20.  
  21. |        A B  C  D E ...
  22. |        |\  /|   /|
  23. |        | \/ |  / |
  24. |        | /\ | /  |
  25. |        |/  \|/   |
  26. |        L    M    N ...
  27.  
  28. |The problem occurs when I wish declare a function which operates on
  29. |all classes derived from both `A' and `C'.  Ideally I'd like to say
  30. |something like (in modified C++ syntax):
  31.  
  32. |     foo(A & C my_obj) { ... }
  33.  
  34. |where `&' indicates a kind of intersection of types.  I can see two
  35. |ways to do fudge this, neither of which I like.
  36.  
  37. Since A and C have no common base, what basis would foo have to deal
  38. with my_obj?  How would it know which one it was? 
  39.  
  40. I think you are looking for a form of multiple dispatch, where the
  41. function called depends upon the type of the argument.  But C++ does
  42. not have dynamic multiple dispatch.
  43.  
  44. You could do it statically, by declaring two functions foo(A) and
  45. foo(B)...
  46.  
  47.  
  48.  
  49. --
  50. +---Robert C. Martin---+-RRR---CCC-M-----M-| R.C.M. Consulting         |
  51. | rmartin@rational.com |-R--R-C----M-M-M-M-| C++/C/Unix Engineering    |
  52. |     (Uncle Bob.)     |-RRR--C----M--M--M-| OOA/OOD/OOP Training      |
  53. +----------------------+-R--R--CCC-M-----M-| Product Design & Devel.   |
  54.