comp.lang.ada
 help / color / mirror / Atom feed
From: "Matthew Heaney" <matthew_heaney@acm.org>
Subject: Re: Inheritance and Polymorphism in Ada !!
Date: 1999/10/15
Date: 1999-10-15T00:00:00+00:00	[thread overview]
Message-ID: <38077a53_4@news1.prserv.net> (raw)
In-Reply-To: 3806DC34.1513E8B1@frqnet.de

In article <3806DC34.1513E8B1@frqnet.de> , Andreas Winckler 
<andreas.winckler@frqnet.de>  wrote:

> Yes, but in my opinion polymorphism is kind of restricted in Ada.

No, there is no restriction.


> See line 16, the type of the referenced object must be known in advance.
> With "pointer.second_field :=1" the compiler fails. It seems that the
> strong typing restricts the features of polyormism in Ada. Any comments?

"Class-wide" programming means programming against all the types in the
class.  When you manipulate an object whose type is Type_A'Class, then
what you're saying is you only care about those attributes that are
common to ALL types.

The field "second_field" is not common to all types in the class
Type_A'Class, so it doesn't make any sense to complain you can't
automatically see it.  If you're interested in that field, then
obviously you want an object whose type is Type_B'Class, or just Type_B.


> Am I wrong?

Yes.


> However, when it comes to real_world_applications like the air traffic
> control systems I do, polymorphism and dynamic memory allocation is a
> DO_NOT anyway.

Yes, it's true that dynamic memory allocation isn't allowed, but Ada was
designed to that you don't need dynamic memory allocation.

There was no reason for you to put the object on the heap.  You could
have said just as easily:

  Object : Type_A'Class := Type_B'(1, 2);

No heap required.

Of course, you don't have to declare you're objects as class-wide,
meaning dynamic dispatch does *not* occur, which means you really *can*
use tagged types in safety-critical systems.  For example:

  Object : Type_B := (1, 2);


--
Why stop at evolution and cosmology, though? Let's make sure that the
schoolkids of Kansas get a really first-rate education by loosening up
the teaching standards for other so-called scientific ideas that are,
after all, just theories. The atomic theory, for example. The theory of
relativity. Heck, the Copernican theory--do we really know that the
universe doesn't revolve around the earth?

John Rennie, Scientific American, Oct 1999




  parent reply	other threads:[~1999-10-15  0:00 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-15  0:00 Inheritance and Polymorphism in Ada !! Chango Cho
1999-10-15  0:00 ` Lutz Donnerhacke
1999-10-15  0:00 ` Ted Dennison
1999-10-15  0:00 ` Andreas Winckler
1999-10-15  0:00   ` Lutz Donnerhacke
1999-10-15  0:00   ` Richard D Riehle
1999-10-15  0:00     ` Matthew Heaney
1999-10-15  0:00       ` Richard D Riehle
1999-10-18  0:00       ` Robert Dewar
1999-10-23  0:00         ` Richard D Riehle
1999-10-24  0:00           ` Robert Dewar
1999-10-24  0:00             ` Brian Rogoff
1999-10-26  0:00               ` Robert Dewar
1999-10-25  0:00             ` Robert A Duff
1999-10-26  0:00               ` Robert Dewar
1999-10-26  0:00                 ` Robert A Duff
1999-10-18  0:00       ` Robert A Duff
1999-10-19  0:00         ` Robert Dewar
1999-10-20  0:00           ` Robert A Duff
1999-10-21  0:00             ` Paul Duquennoy
1999-10-21  0:00             ` Simon Wright
1999-10-21  0:00               ` Robert A Duff
1999-10-21  0:00             ` Robert Dewar
1999-10-22  0:00         ` Matthew Heaney
1999-10-15  0:00   ` Stephane Barbey
1999-10-15  0:00   ` Matthew Heaney [this message]
1999-10-18  0:00     ` Robert A Duff
1999-10-18  0:00       ` Brian Rogoff
1999-10-15  0:00   ` tmoran
1999-10-15  0:00     ` tmoran
1999-10-18  0:00   ` Robert A Duff
replies disabled

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