comp.lang.ada
 help / color / mirror / Atom feed
* Help - trying to understand dynamic dispatching
@ 1999-04-08  0:00 Steve Folly
  1999-04-09  0:00 ` Matthew Heaney
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Steve Folly @ 1999-04-08  0:00 UTC (permalink / raw)


Help! I've been trying to understand how dynamic dispatching works in Ada95,
particularly the syntax required - ie. when and where you need the class
wide types.

I'm not going to explain my problem here - my problem really is "how do you
do it?".
I'm more familiar with the C++ method of virtual functions.

Unless someone wants to explain and perhaps give a concrete example in C++
and it's equivalent Ada95 :-), a helpful push in the direction of a book,
paper or website describing such a beast would be most appreciated.


--
Some me a kipper, I'll be back for breakfast,
Steve Folly
http://www.follysplace.demon.co.uk
donationsto:myaccount@mybank.co.uk






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help - trying to understand dynamic dispatching
  1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
@ 1999-04-09  0:00 ` Matthew Heaney
  1999-04-09  0:00 ` dennison
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Matthew Heaney @ 1999-04-09  0:00 UTC (permalink / raw)


"Steve Folly" <steve@follysplace.demon.co.uk> writes:

> Help! I've been trying to understand how dynamic dispatching works in Ada95,
> particularly the syntax required - ie. when and where you need the class
> wide types.
> 
> I'm not going to explain my problem here - my problem really is "how do you
> do it?".
> I'm more familiar with the C++ method of virtual functions.
> 
> Unless someone wants to explain and perhaps give a concrete example in C++
> and it's equivalent Ada95 :-), a helpful push in the direction of a book,
> paper or website describing such a beast would be most appreciated.


I have converted every C++ program in the GoF Design Patterns book to
Ada95.  You can find them all in the ACM patterns archive (listed by
month of posting).

<http://www.acm.org/archives/patterns.html>


You can subscribe to the patterns list by sending the message body

subscribe patterns <your name>

to the ACM mailing list server.

<mailto:listserv@acm.org>


Some of the early ones I did when I was learning Ada95, so you may be
better of starting from the most recent and working your way backwards.

If you have any questions, just drop me a note, or send your question to
the patterns list.

<mailto:patterns@acm.org>

Matt
<mailto:matthew_heaney@acm.org>





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help - trying to understand dynamic dispatching
  1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
  1999-04-09  0:00 ` Matthew Heaney
@ 1999-04-09  0:00 ` dennison
  1999-04-09  0:00 ` David C. Hoos, Sr.
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dennison @ 1999-04-09  0:00 UTC (permalink / raw)


In article <923610308.5473.0.nnrp-09.c2de848f@news.demon.co.uk>,
  "Steve Folly" <steve@follysplace.demon.co.uk> wrote:
> Help! I've been trying to understand how dynamic dispatching works in Ada95,
> particularly the syntax required - ie. when and where you need the class
> wide types.
>

> Unless someone wants to explain and perhaps give a concrete example in C++
> and it's equivalent Ada95 :-), a helpful push in the direction of a book,
> paper or website describing such a beast would be most appreciated.

Cohen's "Ada as a Second Language" (ISBN 0070116075) goes into this in some
detail. I really didn't understand too well until I played with it myself
though. It is correct that class wide types have to be involved either as a
formal or actual parameter for dynamic dispatching to occur.

...unless there's some wrinkle I've missed.

T.E.D.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help - trying to understand dynamic dispatching
  1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
                   ` (2 preceding siblings ...)
  1999-04-09  0:00 ` David C. Hoos, Sr.
@ 1999-04-09  0:00 ` David Botton
  1999-04-11  0:00 ` Steve Folly
  4 siblings, 0 replies; 6+ messages in thread
From: David Botton @ 1999-04-09  0:00 UTC (permalink / raw)


Take a look on the Ada Source Code Treasury learning section at:

http://www.botton.com/ada/learn

for on-line tutorials and books that can help you in this area.

Also take a look at:

http://www.botton.com/ada/books

for a listing of great Ada books

David Botton


Steve Folly wrote:

> Help! I've been trying to understand how dynamic dispatching works in Ada95,
> particularly the syntax required - ie. when and where you need the class
> wide types.
>
> I'm not going to explain my problem here - my problem really is "how do you
> do it?".
> I'm more familiar with the C++ method of virtual functions.
>
> Unless someone wants to explain and perhaps give a concrete example in C++
> and it's equivalent Ada95 :-), a helpful push in the direction of a book,
> paper or website describing such a beast would be most appreciated.
>
> --
> Some me a kipper, I'll be back for breakfast,
> Steve Folly
> http://www.follysplace.demon.co.uk
> donationsto:myaccount@mybank.co.uk





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help - trying to understand dynamic dispatching
  1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
  1999-04-09  0:00 ` Matthew Heaney
  1999-04-09  0:00 ` dennison
@ 1999-04-09  0:00 ` David C. Hoos, Sr.
  1999-04-09  0:00 ` David Botton
  1999-04-11  0:00 ` Steve Folly
  4 siblings, 0 replies; 6+ messages in thread
From: David C. Hoos, Sr. @ 1999-04-09  0:00 UTC (permalink / raw)



Steve Folly wrote in message <923610308.5473.0.nnrp-09.c2de848f@news.demon.co.uk>...
>Help! I've been trying to understand how dynamic dispatching works in Ada95,
>particularly the syntax required - ie. when and where you need the class
>wide types.
>
>I'm not going to explain my problem here - my problem really is "how do you
>do it?".
>I'm more familiar with the C++ method of virtual functions.
>
>Unless someone wants to explain and perhaps give a concrete example in C++
>and it's equivalent Ada95 :-), a helpful push in the direction of a book,
>paper or website describing such a beast would be most appreciated.
>
There is two small examples which includes dispatching on my FTP site:
ftp://ftp.ada95.com/pub/pet_store.tgz and
ftp://ftp.ada95.com/pub/tagged_types.tgz which illustrate the equivalent
of C++ virtual functions.

In pets.ads, the function Image_Of is declared as abstract, which is like
C++'s pure virtual function.  For any type derived from Pets.Pet_Type,
a concrete implementation must be defined.  The Ada compiler enforces it.
See, for example the file pets-mammals-dogs.adb for one concrete
implementation.

In the tagged_types package, the file messages.ads has the two
following declarations:
   function Image_Of (Item : Message) return String is abstract;
   function Image (Item : Message'Class) return String;

The first is, again, an abstract function for which a concrete
implementation must exist for every type derived from Messages.Message.

The second, is a class-wide function which may be called for any
type derived from Messages.Message, even for derived types not yet existing
at the time the function Image is declared.

The code and the commentary in the source files should make it clear what's
going on.  These examples also illustrate more than just the polymorphic
aspects of Ada95.  I hope you find them helpful.

The last time I suggested someone look at these he found a bug.  Maybe you
will, too!

If you have access to Ada95 for C and C++ Programmers by Samuel Johnston
(ISBN 0-201-40363-3), there is a section starting on page 181, entitled
"6.3.3 Polymorphism and 'Class (virtual functions)" with additional
commentary.







^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Help - trying to understand dynamic dispatching
  1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
                   ` (3 preceding siblings ...)
  1999-04-09  0:00 ` David Botton
@ 1999-04-11  0:00 ` Steve Folly
  4 siblings, 0 replies; 6+ messages in thread
From: Steve Folly @ 1999-04-11  0:00 UTC (permalink / raw)


Thanks to all who replied for their suggestions of examples. I have looked
at these and now have a better
understanding of polymorphism.

I think my main problem was getting around the fact that in C++,
polymorphism is achieved through
virtual functions and using a pointer or reference to a base class. In
Ada95, polymorphism can be
achieved with normal (non-pointer) types. It is using the class wide type
that is crucial.

Thanks again.

Steve Folly <steve@follysplace.demon.co.uk> pleaded in message
news:923610308.5473.0.nnrp-09.c2de848f@news.demon.co.uk...
> Help! I've been trying to understand how dynamic dispatching works in
Ada95,
> <snipped>






^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-04-11  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-08  0:00 Help - trying to understand dynamic dispatching Steve Folly
1999-04-09  0:00 ` Matthew Heaney
1999-04-09  0:00 ` dennison
1999-04-09  0:00 ` David C. Hoos, Sr.
1999-04-09  0:00 ` David Botton
1999-04-11  0:00 ` Steve Folly

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