comp.lang.ada
 help / color / mirror / Atom feed
From: sdl@linus.UUCP (Steven D. Litvintchouk)
Subject: Re: Inheritance and Ada
Date: 17 Dec 87 03:47:00 GMT	[thread overview]
Message-ID: <19902@linus.UUCP> (raw)
In-Reply-To: ephraim@techunix.BITNET's message of 16 Dec 87 20:32:43 GMT

Posting-Front-End: GNU Emacs 18.47.1 of Sun Aug  2 1987 on linus (berkeley-unix)



> I am an Ada beginner so please excuse me if this question is not too
> bright.  I am familiar with other object-oriented languages like C++
> and Lisp Flavours and wish to know if Ada supports inheritance as the
> other two do.  Please reply by e-mail as this newsgroup doesn't arrive
> at our site.

I will both email you my answer and post it to this newsgroup:

Ada does *not* provide direct support for subclassing/inheritance in
the style of Smalltalk, Flavors, etc.  (And yes, I have found this to
be a major limitation of Ada.)

You can *simulate* inheritance in Ada, if you're willing to do some
extra work.  Two techniques are:
  
1.  Use derived types.  This works mostly when the subclass differs
from the parent class in such simple ways as range constraints.

2.  Use generics.  The generic formal parameters correspond to the
"inherited" scope (e.g. methods).  This rather general solution is
admittedly clumsy to program.  However, we at MITRE have worked out
what we believe is a reasonably complete solution to this, for
arbitrary semantic dependency networks of data types (including
cycles; i.e.  mutually recursive data types).

The important thing to watch out for is this:

Languages like Smalltalk & Flavors distinguish between clients (users)
that make instances of a class, and clients that define a subclass of
a class.  In the former case, the instances are true "black boxes";
i.e.  the instance variables are hidden; they can only be modified
indirectly via message sends.

In the latter case (inheritance), the subclass "sees" everything,
including the instance variables.  This makes it easy to add methods
to the subclass that manipulate the instance variables defined in the
parent class.  (Although there has been some discussion that this much
visibility in Smalltalk is overkill, and you could conceivably make do
with less.)

This distinction between those users of a class who make instances,
and those who make subclasses, does not exist in Ada.  Regardless of
whether you try to simulate inheritance via derived types, generics,
etc., you find that there is a conflict in Ada between encapsulation
and inheritance.

If you defined a "class" (abstract data type) in Ada, whose types are
private (i.e. instance variables are encapsulated or hidden), then if
you "inherit" this into a subclass, you have no way to get at the
instance variables of the parent class from the subclass.  On the
other hand, you could make the abstract data type definition of the
parent class visible.  Then its instance variables can be "inherited,"
but you have to violate encapsulation to accomplish this. So the
instance variables of each instance of the class are not protected
from manipulation by others.


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

  reply	other threads:[~1987-12-17  3:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-12-16 20:32 Inheritance and Ada Ephraim Silverberg
1987-12-17  3:47 ` Steven D. Litvintchouk [this message]
1987-12-24 15:47   ` Brad Cox
1987-12-25 20:28     ` Bertrand Meyer
1987-12-28  0:52       ` Steven D. Litvintchouk
1987-12-28  3:21     ` Litvintchouk
1988-01-05 20:27     ` Chris Henrich
1988-01-06 20:36       ` David E. Emery
1988-01-07 13:58       ` Kari Syst{
  -- strict thread matches above, loose matches on Subject: below --
1987-12-28 15:38 Mike Feldman
1987-12-29 15:28 ` Richard Pettit
replies disabled

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