comp.lang.ada
 help / color / mirror / Atom feed
From: hathawa2@marshall.edu (Mark S. Hathaway)
Subject: Re: Ada Objects  Help!
Date: 20 Jan 95 13:41:50 EDT
Date: 1995-01-20T13:41:50-04:00	[thread overview]
Message-ID: <1995Jan20.134150@hobbit> (raw)
In-Reply-To: 1995Jan16.132400@lglsun.epfl.ch

> In article <1995Jan16.132400@lglsun.epfl.ch>,
> nebbe@lglsun.epfl.ch (Robb Nebbe) writes:

>> In article <3f9g1u$j4m@nps.navy.mil>, swdecato@nps.navy.mil writes:

>> I wan't to duplicate the following C++ code in Ada.
>> 
>> -------------------------------------------------------------------
>> #include <iostream.h>
>> class myclass {
>>    public:
>>        myclass(int);
>>        void display();
>>    private:
>>        int dataelement;
>>    };
>> 
>>    void myclass::display() {
>>       cout << dataelement;
>>    }
>> 
>>    int main()
>>    {
>>    myclass *myptr = new myclass(10);
>>    myptr->display();
>>    return 1;
>>    }
>> ------------------------------------------------------------------------

> As usual the major problem is how much of the information in your
> example is noise and how much is really something you would like
> to know. With out more information on the context I'm going to make
> a _guess_ as to what you want to know (correct me if I'm wrong).
> 
> package P is  -- Just the specification
>    type T is tagged private;
>    function Create( X : Integer ) return T;
>    procedure Display( X : T );
> private
>    type T is tagged
>       record
>          Data_Element : Integer;
>       end record;
> end My_Package;
> 
> with P; use P;
> procedure Example is
>    Object : T'Class := Create( 10 );
> begin
>    Display( Object );
> end Example;
> 
> Semantically this is probably as close as you can get to your C++
> example. In Ada the pointer isn't needed to dispatch since Ada
> differentiates between specific types and class-wide types. Moreover,
> in Ada there aren't any problems with your objects getting truncated
> so this solution works just fine. There are also other minor variations
> possible, depending on what you really want to accomplish.

>> How can Ada be object oriented if you always have to pass the data to the
>> function? 

> In C++ you must also pass the data to a function; the only difference
> is in the syntax. Object.Operation; is no different semantically than
> Operation( Object );


These examples looks odd to me.  I'm not very knowledgeable of Ada or C++,
but I know pornography when I see it (oops, that's another discussion).  :-)

It's not obvious if 'myclass(int)' is creating a list of objects of type
myclass or if it's assigning 10 --> dataelement.  It's not very eloquent.
Then the Ada example changes 'myclass(int)' to 'Create(X : Integer) return T'
with the added complexity of defining T.  It looks wrong or overly complex.
And it's comparable in length to the C++ version only because the class
implementation isn't given.  Does the Ada example even create an object?

Here's my idea of how it should look.

spirit myclass is
  proc assign ( x is in integer );  -- assign value referenced by x to myclass
  proc display ();
end myclass;

body myclass is
  var dataelement is integer;
  proc assign ( x is in integer ) is
    dataelement := x;
  end assign;
  proc display () is
    out.write(dataelement);
  end display;
end myclass;

program example1 is
-- This example demonstrates the pointer method the C++ example used.
  var op is pointer to myclass;
begin
  new(op);      -- create instance of an object of type to which op can point
  op->assign(10);
  op->display();
end example1.

program example2 is
-- This example demonstrates the direct usage of an object.
  obj o is myclass;      -- create one instance of the object
begin
  o.assign(10);
  o.display();
end example2.

Isn't this closer to what the C++ example is "saying"?


Mark S. Hathaway       <hathawa2@marshall.edu>



  parent reply	other threads:[~1995-01-20 17:41 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3f9g1u$j4m@nps.navy.mil>
     [not found] ` <D2H5un.FEr@nntpa.cb.att.com>
     [not found]   ` <3fcs59$70s@nps.navy.mil>
     [not found]     ` <3ff186$c19@gnat.cs.nyu.edu>
1995-01-17 17:57       ` ADA Objects Help! Mats Weber
1995-01-18 17:47         ` Robert Dewar
1995-01-20 16:04           ` Mats Weber
1995-01-21 18:59             ` Robert Dewar
1995-01-23 12:03               ` Robb Nebbe
1995-01-25 20:44                 ` Mats Weber
1995-01-25 20:44               ` Mats Weber
1995-01-27  4:03                 ` Robert Dewar
1995-01-26  3:36           ` swdecato
     [not found]         ` <3fhggr$11dp@watnews1.watson.ibm.com>
     [not found]           ` <Mats.Weber-1901951739360001@mlma11.matrix.ch>
1995-01-20 17:22             ` Norman H. Cohen
1995-01-23 16:37               ` Mats Weber
1995-01-25 20:44               ` Mats Weber
1995-01-27  4:05                 ` Robert Dewar
1995-01-19 11:57   ` Robert M. Wilkinson
1995-01-22 18:06     ` Robert Dewar
1995-01-24 22:18       ` Norman H. Cohen
1995-01-25  1:26         ` swdecato
1995-01-25 18:18           ` Bob Kitzberger
1995-01-25 20:11             ` Bob Kitzberger
1995-01-26 15:31           ` Norman H. Cohen
     [not found]           ` <D330pK.M1@nntpa.cb.att.com>
1995-01-28 21:46             ` John DiCamillo
1995-01-30 14:13               ` David Emery
1995-01-30 22:50               ` Subject/Object Confusion Syndrome [was: Ada Objects Help] John Volan
1995-02-01 14:33                 ` Norman H. Cohen
     [not found]                   ` <D3DpJu.4nK@swlvx2.msd.ray.com>
     [not found]                     ` <D3H7J3.B2x@inmet.camb.inmet.com>
1995-02-06 10:32                       ` Robb Nebbe
     [not found]                     ` <3gu21g$ch@portal.gmu.edu>
1995-02-06 14:01                       ` John Volan
1995-02-01 22:37                 ` Maarten Landzaat
     [not found]                   ` <3h1ahp$gf5@gnat.cs.nyu.edu>
     [not found]                     ` <3h3jmp$1h1@Starbase.NeoSoft.COM>
1995-02-07 14:39                       ` John Volan
1995-02-09  2:25                         ` David Weller
1995-01-29 18:19             ` ADA Objects Help! mat
     [not found]               ` <1995Feb5.180601@hobbit>
1995-02-07 23:04                 ` Subject/Object Confusion Syndrome [was: Ada Objects Help] John Volan
1995-01-25  9:48       ` ADA Objects Help! mat
1995-01-23 10:01     ` calling syntax (was Re: Ada Objects) Robb Nebbe
1995-01-23 18:08       ` John DiCamillo
1995-01-23 23:47     ` ADA Objects Help! Ed Osinski
1995-01-25  6:19       ` David O'Brien
     [not found] ` <1995Jan16.132400@lglsun.epfl.ch>
     [not found]   ` <131279@cup.portal.com>
1995-01-20 16:52     ` Ada " Robert Dewar
1995-01-22 18:30       ` Tucker Taft
1995-01-24 22:09         ` Jacob Sparre Andersen
1995-01-26 16:20           ` Robert A Duff
1995-01-27 17:04             ` Robert A Duff
1995-01-27 19:58             ` Tucker Taft
1995-01-20 17:41   ` Mark S. Hathaway [this message]
1995-01-23 10:41     ` Robb Nebbe
1995-01-23 11:53     ` Stephane Barbey
replies disabled

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