comp.lang.ada
 help / color / mirror / Atom feed
* Re: Inheritance and Ada (and access types and generics)
@ 1987-12-28  1:09 Litvintchouk
  0 siblings, 0 replies; only message in thread
From: Litvintchouk @ 1987-12-28  1:09 UTC (permalink / raw)



In article <255@hub.ucsb.edu> bertrand@hub.ucsb.edu (Bertrand Meyer) writes:

> I am surprised none of the discussants quoted my article, ``Genericity
> versus Inheritance'', which addresses precisely this topic. The paper
> was published in the Proceedings of the first OOPSLA conference
> (OOPSLA 86, Portland; SIGPLAN Notices, 21, 11, pp. 391-405). A revised
> version is due for publication in the Journal of Pascal, Ada and Modula-2.
> 
> 	The article explores the relationship between Ada-like generic modules
> and inheritance as it exists in O-O languages. It shows the respective
> benefits of both techniques and explains how they have been (cleanly,
> I think) combined in the Eiffel language and environment.
> 

My apologies, I was at OOPSLA '86 and thought your paper was
excellent.  (and there have been other good papers on the subject as
well.)

> This does not prevent data structures from being polymorphic:
> for example, if an entity is declared as
> 
> 		fs: STACK [FIGURE]
> 
> then you may push onto the corresponding object a point,
> a circle etc., assuming POINT, CIRCLE
> etc. are descendant classes (in the sense of inheritance) of FIGURE.
> However you may not push onto fs, say, an integer....

Actually, attempting to simulate this kind of polymorphism in Ada is
even clumsier than your paper portrayed it.  As you pointed out, you do
end up having to define variant record types (whose variants include
all the polymorphic subclasses) and other case analyses all over the
place.  

Even worse, however, Ada does not let you instantiate the (generic)
STACK package with an unconstrained variant record type, if the
package requires the type to be constrained (as is often the case).
Thus in Ada, I find I am continually forced to play this game of
instantiating the generic with an access (pointer) type to the variant
record type.  Not only is this clumsy, but it requires you to use
allocators ("new") to create the instances of the record type, opening
up all the performance issues of using dynamic allocation in embedded
computer systems software.

Sadly, you are often forced to use access types in Ada, even when
you're not particularly interested in dynamic storage, but just to get
around some of the quirks of Ada's type model.  Another example:  you
can't instantiate a generic with an incomplete type.  So you end up
having to fake it by instantiating the generic with an access type
that points to the incomplete type, and you can guess the rest.


Steven Litvintchouk
MITRE Corporation
Burlington Road
Bedford, MA  01730

Fone:  (617)271-7753
ARPA:  sdl@mitre-bedford.arpa
UUCP:  ...{cbosgd,decvax,genrad,ll-xn,philabs,security,utzoo}!linus!sdl

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1987-12-28  1:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1987-12-28  1:09 Inheritance and Ada (and access types and generics) Litvintchouk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox