home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / ada / 2607 < prev    next >
Encoding:
Text File  |  1992-09-14  |  5.4 KB  |  118 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!uakari.primate.wisc.edu!ames!think.com!linus!linus.mitre.org!linus!mbunix!eachus
  3. From: eachus@Dr_No.mitre.org (Robert I. Eachus)
  4. Subject: Re: MI - clutching at straws
  5. In-Reply-To: pk@rwthi3.informatik.rwth-aachen.de's message of Wed, 9 Sep 92 14:24:34 GMT
  6. Message-ID: <EACHUS.92Sep14151942@Dr_No.mitre.org>
  7. Sender: news@linus.mitre.org (News Service)
  8. Nntp-Posting-Host: dr_no.mitre.org
  9. Organization: The Mitre Corp., Bedford, MA.
  10. References: <EACHUS.92Sep8135021@Dr_No.mitre.org>
  11.     <1992Sep9.142434.3940@Urmel.Informatik.RWTH-Aachen.DE>
  12. Date: Mon, 14 Sep 1992 20:19:42 GMT
  13. Lines: 103
  14.  
  15. In article <1992Sep9.142434.3940@Urmel.Informatik.RWTH-Aachen.DE> pk@rwthi3.informatik.rwth-aachen.de (Peter Klein) writes:
  16.  
  17.  > Unfortunately, your arguments don't hold in my example, where several
  18.  > extensions of the same base type are combined. The resulting type is
  19.  > essentially the base type augmented by an arbitrary subset of the possible
  20.  > extensions. The problems you mentioned cannot arise in this context.
  21.  > Furthermore, it is pretty awkward to simulate such behaviour without MI.
  22.  
  23.     But it is exactly that case...the (base) type is extended with lists
  24. and trees, and then these extensions are combined.  (It is hard not to
  25. use nasty words to relieve frustration at this point, but I know that
  26. this is a hard enough to understand mechanisms like type extension and
  27. inheritance, and the subtile differences in mechanisms discussed here
  28. tend to rapidly convert any brain into jelly, but bear with me.)
  29.    
  30.     Part of the problem is semantic.  I think Tucker will be glad to
  31. explain to you how Ada implements multiple inheritance, while most of
  32. us use MI to mean something other than generic instantiation, but
  33. Tucker does have a point.  The Ada 9X mechanisms are safer and more
  34. general than those offered by most instances of MI, but it does
  35. require more thinking up front by the designer of a mix-in.
  36.  
  37.  > Not true. Inheritance is the more powerful feature. Dynamical binding cannot
  38.  > be done with genericity; you'll never get true polymorphism without
  39.  > inheritance. But I don't think this is the question. Genericity and
  40.  > inheritance both have their uses, and most of the time the design makes
  41.  > clear which of them is appropriate in a given situation. If you think that
  42.  > inheritance is not *really* needed, I can accept that. But my original
  43.  > question was: What do I loose when I have SI only?
  44.  
  45.      I assume that you left a word out above, since in my post I did
  46. say that inheritance is sometimes necessary, it is union style
  47. multiple inheritance that is unnecessary in Ada or any other language
  48. with sufficiently powerful generic capabilities.
  49.  
  50.  > In what way does the lack of MI affect the usefulness of the whole
  51.  > inheritance idea? *If* I think extensions of a base type should be
  52.  > done using inheritance, how do I solve the problem of combining
  53.  > independent extensions afterwards?
  54.  
  55.      You don't.  But in general it is always wrong to combine
  56. extentions which were not intended to be combined.  Ada 9X will give
  57. you a choice of several combining styles, and in general the language
  58. will insure that mixtures which are permitted will work.  However,
  59. since generics mean that the difference between a combining extension
  60. and normal single inheritance is a few words, you should honor the
  61. wishes of the type designer and assume that two types which can't be
  62. mixed shouldn't be mixed:
  63.  
  64.       with Parent;
  65.       package New_Abstraction is
  66.         type Child is new Parent.Abstraction with private;
  67.         -- syntax under construction, very subject to change.
  68.         ...
  69.       private
  70.         ...
  71.       end New_Abstraction;
  72.  
  73.       with Parent;
  74.       generic
  75.         type Abstraction is new Parent.Abstraction;
  76.         -- see note above on syntax
  77.       package MixIn is
  78.         type Child is new Abstraction with private;
  79.         ...
  80.       private
  81.         ...
  82.       end MixIn;
  83.  
  84.      Now New_Abstraction uses single inheritance and can't mix with
  85. another similar extension. MixIn, with just a few lines different in
  86. its specification, can mix with similar type extensions OR with
  87. New_Abstraction: 
  88.  
  89.      with New_Abstraction, MixIn;
  90.      package Mixed_In is new MixIn(New_Abstraction.Child);
  91.  
  92.      (Note that if you do this, the body of MixIn can access the
  93. operations of its parent, in this case New_Abstraction.Child, as can
  94. users who with Mixed_In.  However, if Mixed_In hides an operation of
  95. New_Abstraction.Child, whether or not dispatching is involved, the user
  96. will have to with New_Abstraction and do a type conversion to access
  97. the "parent" operation.)
  98.  
  99.      If it weren't for the fact that generics are IMHO a much more
  100. powerful tool than inheritance, I could argue that using generics to
  101. implement mix-ins is like using a sledgehammer to swat flies.  But
  102. since Ada has all of the necessary support for generics for other
  103. reasons, it seems silly to talk about adding MI because maybe someday
  104. someone will think of an application where classical MI is
  105. significantly better.  (In my opinion, and that of a lot of other
  106. software engineers, the ability to express "Watch it!" in the code is
  107. a definite advantage.  In Ada 9X using inheritance in a non-generic
  108. fashion will be a strong warning message that this new type has more
  109. than mix-in semantics.)
  110.  
  111. --
  112.  
  113.                     Robert I. Eachus
  114.  
  115. with STANDARD_DISCLAIMER;
  116. use  STANDARD_DISCLAIMER;
  117. function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...
  118.