comp.lang.ada
 help / color / mirror / Atom feed
From: Mike Stark <michael.e.stark@gsfc.nasa.gov>
Subject: Re: polymophism
Date: 1996/11/21
Date: 1996-11-21T00:00:00+00:00	[thread overview]
Message-ID: <329493AD.4A35@gsfc.nasa.gov> (raw)
In-Reply-To: 570f4b$rbu@queeg.apci.net


James O'Connor wrote:
> 
<snip>
> 
>  In Ada (83 or 95) the standard mechanism for implementing an Object seems to
>  be to have a package that wraps a type declaration and a set of operations on
> that type.  The type declaration is typically a record that describes the names and
>  types of the attributes of the Object.  (I'll try to use example code but I haven't
> programmed in Ada in years...)
> 
> package Airplane_Package is
> 
>         type AIRPLANE_TYPE is private;
> 
>         function Get_Tail_Number (Airplane : AIRPLANE_TYPE) returns String;
> 
>         procedure Take_Off (Airplane : AIRPLANE_TYPE);
> 
>         private
>                 type AIRPLANE_TYPE is record
>                         Tail_Number : STRING (1 .. 20) := "";
>                         Model_Design_Series : STRING (1 .. 20) := "";
>                 end record;
> 
> end Airplane_Package;
> 
> with Airplane_Package
> 
> procedure Test is
> 
>         My_Airplane : Airplane_Package.AIRPLANE_TYPE;
>         My_TailNumber : STRING (1 .. 20);
> 
> begin
> 
>         My_TailNumber := Airplane_Package.Get_Tail_Number(My_Airplane)
> 
> end Test;
> 
> My question is "where's the object?"  My_Airplane isn't an object because
> it only defines the state of an Airplane.  It does not define the operations
> available for the Airplane.  The package defines the operations.  But the package
>  isn't an object (the package doesn't even have runtime existance).  In this case
>  you could say that the package is close to being a class.

A better question might be "where's the class?"  The answer is that your
private record type is analogous to a C++ or Java class (can't speak for
any other languages), with the components representing instance
variables and "primitive operations" the member functions.  The
primitive operation is a concept added for Ada 95, and it is one in the
same package as your record type that has an argument of that type. 
Then My_Airplane in procedure test is indeed an object, although you
could also create

type Airplane_Ptr is access Airplane_Type;  -- in Airplane_Package

and

  My_Airplane: Airplane_Package.Airplane_Pointer := new
Airplane_Package.Airplane;

to allocate an object.

To be truly analogous to a class in C++ or Java, you need to use the Ada
95 "tagged" keyword to make types extendable, and class-wide programming
to define dispatching operations.  I will leave the description of these
features to the experts.

This is more than a theoretical discussion.  I have been doing some
prototyping with 
AppletMagic, a tool that compiles Ada into Java byte codes.  When you
run the "javap"
command to disassemble a class file into Java source, Ada code
containing a tagged 
record maps directly to a Java class.

Mike

Note I don't want to get into the fruitless religious war over whether

The_object.Do_something (now); 

or 

Do_Something (The_Object, Now)

is better.




  reply	other threads:[~1996-11-21  0:00 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-18  0:00 polymophism AGBOH CHARLES
1996-11-19  0:00 ` polymophism Darren C Davenport
1996-11-21  0:00   ` polymophism Robert I. Eachus
1996-11-21  0:00   ` polymophism James O'Connor
1996-11-21  0:00     ` Mike Stark [this message]
1996-11-22  0:00       ` polymophism Klaus Brouwer
1996-11-23  0:00         ` polymophism James O'Connor
1996-11-25  0:00         ` polymophism Richard Riehle
1996-11-22  0:00       ` polymophism Norman H. Cohen
1996-11-22  0:00     ` polymophism Norman H. Cohen
1996-11-23  0:00       ` polymophism James O'Connor
1996-11-22  0:00         ` polymophism Matthew Heaney
1996-11-25  0:00           ` polymophism Don Harrison
1996-11-25  0:00           ` polymophism Joachim Durchholz
1996-11-26  0:00             ` polymophism Don Harrison
1996-11-25  0:00       ` Is Ada an OO Language? (was => Re: polymophism) Richard Riehle
1996-11-25  0:00         ` James S. Rogers
1996-11-23  0:00     ` polymophism John Howard
1996-11-22  0:00   ` polymophism Jon S Anthony
1996-11-22  0:00     ` polymophism Robert A Duff
1996-11-23  0:00   ` polymophism Jon S Anthony
1996-11-24  0:00   ` polymophism Robert B. Love 
1996-11-27  0:00   ` Is Ada an OO Language? (was => Re: polymophism) Robert I. Eachus
  -- strict thread matches above, loose matches on Subject: below --
1996-11-26  0:00 polymophism Peter Hermann
1996-11-26  0:00 ` polymophism John Howard
1996-11-26  0:00 ` polymophism Peter Hicks
1996-11-26  0:00   ` polymophism Peter Hermann
1996-11-29  0:00 ` polymophism Richard Riehle
replies disabled

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