comp.lang.ada
 help / color / mirror / Atom feed
From: Andre Spiegel <spiegel@berlin.informatik.uni-stuttgart.de>
Subject: Re: Ada95 OOP Questions
Date: 1996/07/28
Date: 1996-07-28T00:00:00+00:00	[thread overview]
Message-ID: <lhmspac4law.fsf@berlin.berlin.informatik.uni-stuttgart.de> (raw)
In-Reply-To: 4tf3l4$4hu@masala.cc.uh.edu


Spasmo writes:

> Well after looking at Barnes' Ada95 book and checking out the
> OOP sections I noticed that the Objects in Ada95 seem to
> consist purely of data, and no methods seem to be involved
> so that you have to pass these objects to functions in order
> to get stuff done.  Am I wrong in this (or did I somehow 
> miss something again?).

Ada Objects "consist" of both data and methods, just like in any other
OOP language.  Ada calls the methods "primitive subprograms", and they
are (roughly) defined as those subprograms

  "that are explicitly declared immediately within the same
   package_specification and that operate on the type." (RM95 3.2.3;6)

So, to translate your C++ example into equivalent Ada (not just
"simulating" it!), you can write


   package Persons is

      type Person is tagged private;

      procedure Walk (P : Person);
      procedure Talk (P : Person);
      procedure Eat  (P : Person);

   private

      type Person is tagged
         record
            Age  : Integer;  -- rather "Natural", I'd suggest 
                             -- (C++ doesn't have this)
            Name : String (1..256);
         end record;

   end Persons;


What should be pointed out is that C++ and Ada use slightly different
abstractions.  In C++, you have "classes" and "objects" (but sometimes
a class is referred to as an object, too); whereas in Ada you have 
"packages", "types", "classes of types", and "objects".  For a very
good discussion of this, see Tucker Taft's answer to Question 5.1 in
the Ada Programming FAQ (http://lglwww.epfl.ch/Ada/FAQ/programming.html).

Hope this helps,

Andre Spiegel
University of Stuttgart, Germany




  reply	other threads:[~1996-07-28  0:00 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-28  0:00 Ada95 OOP Questions Spasmo
1996-07-28  0:00 ` Andre Spiegel [this message]
1996-07-28  0:00   ` Spasmo
1996-07-29  0:00     ` Thomas Kendelbacher
1996-07-31  0:00       ` Spasmo
1996-08-01  0:00         ` Thomas Kendelbacher
1996-08-02  0:00         ` Gene Ouye
1996-08-01  0:00       ` Jon S Anthony
1996-07-30  0:00     ` David Wheeler
1996-07-31  0:00       ` Spasmo
1996-07-30  0:00     ` Ken Garlington
1996-08-04  0:00       ` Spasmo
1996-07-28  0:00 ` David C. Hoos, Sr.
1996-07-28  0:00   ` Spasmo
1996-07-29  0:00 ` Andre Spiegel
1996-07-29  0:00   ` Thomas Kendelbacher
1996-08-02  0:00     ` Robert Dewar
1996-08-05  0:00       ` Thomas Kendelbacher
1996-08-06  0:00         ` Robert Dewar
1996-08-06  0:00           ` Thomas Kendelbacher
1996-08-06  0:00             ` Robert A Duff
1996-08-07  0:00               ` Robert Dewar
1996-08-08  0:00                 ` Robert A Duff
1996-08-09  0:00                   ` Robert Dewar
1996-08-12  0:00             ` Robert I. Eachus
1996-08-08  0:00           ` Theodore E. Dennison
1996-08-09  0:00             ` Robert Dewar
1996-08-12  0:00             ` Joel VanLaven
1996-08-06  0:00         ` Robert I. Eachus
1996-08-10  0:00         ` Chris Morgan
1996-07-29  0:00   ` David Wheeler
1996-07-30  0:00     ` Spasmo
1996-07-30  0:00     ` Spasmo
1996-07-30  0:00 ` Andre Spiegel
1996-07-30  0:00 ` Robert I. Eachus
1996-07-30  0:00 ` Andre Spiegel
1996-08-01  0:00 ` Jon S Anthony
1996-08-13  0:00 ` Eric C. Newton
1996-08-14  0:00 ` Eric C. Newton
1996-08-14  0:00 ` Jon S Anthony
1996-08-14  0:00 ` Ken Garlington
1996-08-21  0:00 ` Jon S Anthony
  -- strict thread matches above, loose matches on Subject: below --
1996-08-08  0:00 W. Wesley Groleau (Wes)
1996-08-20  0:00 Farshad Nayeri
1996-08-21  0:00 ` Jon S Anthony
1996-08-20  0:00 Farshad Nayeri
replies disabled

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