comp.lang.ada
 help / color / mirror / Atom feed
From: cosc19z5@Bayou.UH.EDU (Spasmo)
Subject: Re: Ada95 OOP Questions
Date: 1996/07/28
Date: 1996-07-28T00:00:00+00:00	[thread overview]
Message-ID: <4tgi88$5fi@Masala.CC.UH.EDU> (raw)
In-Reply-To: lhmspac4law.fsf@berlin.berlin.informatik.uni-stuttgart.de


Andre Spiegel (spiegel@berlin.informatik.uni-stuttgart.de) wrote:
: 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?).


[Snip]

: 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)

Or even better, a subtype.  That's what I like about Ada.



:             Name : String (1..256);
:          end record;

:    end Persons;


Well here's the thing though, from what I'm seeing when you
use the package you'd need to pass the parameters to the
subprograms rather than having the data encapsulated.  For
instance in C++ you'd do the following:

	Person p;
	p.walk();
	p.talk();
	p.eat();

But with the above you'd do something like the following:
(Any Ada code provided may be slightly erroneous, I just want
to give a general idea of what I think I understand hence not
checking much).


with Persons;

procedure Main is

	P : Persons.Person;

begin
	Persons.Walk(P);
	Persons.Talk(P);
	Persons.Eat(P);
end Main;

Correct me if I'm wrong on this.  So you're still passing parameters
which means that data and subprograms are still 2 different entities
which sorta hurts the abstraction, rather than in say C++ where 
you've got a unified object.   

That's pretty much what I was talking about.  I'm not saying that
one is necessarily worse than the other, I was just wondering if
there was a rationale for doing it that particular way in Ada
rather than a unified object that was like a combination of 
data and subprograms that enabled it to smoothly simulate an
entity?

Also there's another slight difference -- inheritance.  From
what I'm seeing, if we wanted to create say a SuperPersons
package that inherited from persons we'd create a new package
called SuperPerson, then we'd with the Persons package, and
provide "wrappers" for everything defined in the Persons
package right?  Then we'd of course inherit from the data
types and add in any new functionality that we wanted to,
am I correct?

For example here's a crude idea of what I'm talking about:

with Persons;
package SuperPersons is

	type SuperPerson is tagged private;

		procedure Walk(SP : SuperPerson);
		procedure Talk(SP : SuperPerson);
		procedure Eat(SP : SuperPerson);

	private

	type SuperPerson is new Persons.Person with
		record
			SuperPowers : Power;
		end record;

end SuperPersons;

then all our procedures like Walk, Talk, Eat, etc... would need
to call their predecessors right?  For instance:

package body SuperPersons is

	procedure Walk(SP : SuperPerson) is
	begin
		Persons.Walk(SP);
	end Walk;


	...


end SuperPersnos;

and so forth (we could inline them)

Am I correct or can we in fact inherit operations without manually
providing wrappers for the predecessors?



: 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).

Well what I learned in C++ was that "class" referred to the declaration/
definition, whereas an object is an instance of a class.  So using
my old example, Person is a class, but p is an object since it's an
instance of Person.  Still that is kinda moot since we're more concerned
with Ada rather than C++.  I'll look at Question 5.1 again (I skimmed
over certain parts of the FAQ last time I read it which was when
I was trying to find out more about Ada to see whether or not I'd
want to program in it).


: Hope this helps,

It did, thanks.



: Andre Spiegel
: University of Stuttgart, Germany

--
Spasmo
"Everyone has secrets, but sometimes you get caught,
 So if it's just between us, my silence can be bought"
	"Blackmail" by Sloppy Seconds





  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
1996-07-28  0:00   ` Spasmo [this message]
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   ` David Wheeler
1996-07-30  0:00     ` Spasmo
1996-07-30  0:00     ` Spasmo
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-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 ` Ken Garlington
1996-08-14  0:00 ` Jon S Anthony
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