comp.lang.ada
 help / color / mirror / Atom feed
* Ada95 OOP Questions
@ 1996-07-28  0:00 Spasmo
  1996-07-28  0:00 ` David C. Hoos, Sr.
                   ` (11 more replies)
  0 siblings, 12 replies; 46+ messages in thread
From: Spasmo @ 1996-07-28  0:00 UTC (permalink / raw)



Hi.

	First off thanks for all the help I've gotten here already.
I'm currently cranking out some code to get familiarized with Ada
and it's going wonderfully.  Now with that in mind what I have
to ask is a bit long winded and maybe a bit vague, but I'll try
to put it as best as I can.

Ok, with regards to OOP, my previous experience has been with
C++.  In that language when you declare a class, it consists of
data (which can be at various visibility levels (ie: private)),
and methods which operate on the data in the class.  What this
results in is an object (loose use) that has its own actions
and its own attributes so that it's a self contained entity
so to speak.  For instance here's a crude idea:

	class Person {
		public:
			void Walk();
			void Talk();
			void Eat();
		private:
			int Age;
			char Name[256];
	};

When an instance of Person is declared, you just make calls
to the functions provided in that class and all the data
associated with Person is kept inside it and manipulated in it.
You can of course inherit, use polymorphism, etc...

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

In any case I've been looking at using private Objects inside
packages and using these objects as package-global variables
to all the procedures/functions involved so that one can
simulate this sort of behavior, although the simulation
isn't perfect.  Well my other question has to do with
whether or not I should do this?  I mean I have a decent
grasp of using Ada for programming, but am I truly programming
in Ada?  Am I trying to program in C++, but I just happen to
be using Ada to do it?  What is the consensus on this, and
also would anyone describe the philosophy behind this
implementation of OOP?

I'm being careful because I also was confused as to tasks not
seeming to employ time-slices in my implementation only to
realize that it was a blessing in disguise, so I'm approaching
this OO implementation in the same way, namely that there
is something inherent that I am not getting that makes this
a very good thing.

Thanks and I hope my question was somewhat understandable.


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





^ permalink raw reply	[flat|nested] 46+ messages in thread
* Re: Ada95 OOP Questions
@ 1996-08-08  0:00 W. Wesley Groleau (Wes)
  0 siblings, 0 replies; 46+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-08-08  0:00 UTC (permalink / raw)



You also have a readability question with regard to the syntax you've
been discussing.  If  Fred is type (class) Person  and  Fido is Dog, then at
first glance what would be the "intuitive" output of the following?

   C++   -   Fred.bite(Fido)           Ada   -   Persons.Bite(Fred,Fido);

Is it  "Yelp!"  or  "You miserable mutt!"   ?    :-)
Not a very good example, but what I'm getting at is, if you're using
English words for your identifiers, then English word order can reinforce
or work against the meaning in either case.  In previous posts,

   C++      Fred.eat;                 Ada        Persons.Eat(Fred);

If these are equivalent, perhaps the Ada translation should be
                                      Persons.Eating_Should_Be(Fred);
:-)

Now set that foolishness aside.  Do you want to make your Ada look like
C++ ?  Without giving up arrays and linked lists?  Although they weren't
intended for this, protected types/objects can do it!  They can have
not only functions, but procedures and entries.

protected type Person is  -- maybe 'does' should be a synonym for 'is' :-)
  procedure Eat;
  procedure Sleep;
  procedure Work;
  -- is there more to life?
end Person;

type Crowd is array (Natural range <>) of Person;

-- I am sure the rest is obvious....

... and even Ada-83 could do it with task types, provided identifiers
    were carefully chosen.  Not that I would necessarily recommend it,
    but it may in some designs model the real world better than
    non-concurrent objects.



---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Hughes Defense Communications (MS 10-40)                 Home: 219-471-7206
Fort Wayne,  IN   46808                  (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 46+ messages in thread
* Re: Ada95 OOP Questions
@ 1996-08-20  0:00 Farshad Nayeri
  1996-08-21  0:00 ` Jon S Anthony
  0 siblings, 1 reply; 46+ messages in thread
From: Farshad Nayeri @ 1996-08-20  0:00 UTC (permalink / raw)
  Cc: farshad, kalsow, steve


Eric Newton said:

> The point of the (deleted) example was to show that 
> a package is just a namespace, and that multiple classes 
> can live in that namespace, and that the features of 
> the class do not need to be visibly associated
> with the dispatch object.  Matrixes encapsulates 
> Matrix *and* Vector types. I can list the Matrix and 
> Vector operations willy-nilly within this namespace.  

> In C++/Modula-3 I must list the operations on
> the private state of Matrix within the Matrix class. 
> I must list the operations on the private state of 
> Vector within the Vector class.
> There is visible association of dispatch methods and type.

While this may be true of C++'s, it is an inaccurate
statement about Modula-3's organization of namespaces and 
visibility of class features. In fact, much care went 
into designing namespaces and avoiding problems in the 
C++ "public/private/protected/friend" model as you describe. 

Modula-3 has separate mechanisms for encapsulation (modules & 
interfaces) vs. inheritance and dispatching (object types). 
An implementor can define an interface which reveals partial 
information about one or more object types; clients can import
only the necessary features by importing the interface that
reveals the right kind of information about (one or more) types.
Anyone with the right level of access to a group of classes, 
that is, anyone who imports the right "private" interface 
to a module, can access the private state of those classes
as prescribed by the implementor of the interface.

Steve Freeman has written a nice article for Dr. Dobb's Journal,
comparing the encapsulation and grouping facilities of Ada95, 
C++, Eiffel, and Modula-3. He addresses precisely the kinds of issues that
Eric mentioned and goes through code examples to illustrate his
point. A copy of the article is available via the Modula-3 home page.

	http://www.research.digital.com/SRC/modula-3/html/

Regards, -- Farshad

Disclaimer: I am biased!
--
Farshad Nayeri
Critical Mass, Inc.
http://www.cmass.com/




^ permalink raw reply	[flat|nested] 46+ messages in thread
* Re: Ada95 OOP Questions
@ 1996-08-20  0:00 Farshad Nayeri
  0 siblings, 0 replies; 46+ messages in thread
From: Farshad Nayeri @ 1996-08-20  0:00 UTC (permalink / raw)
  Cc: farshad, kalsow, steve


Eric Newton said:

> The point of the (deleted) example was to show that 
> a package is just a namespace, and that multiple classes 
> can live in that namespace, and that the features of 
> the class do not need to be visibly associated
> with the dispatch object.  Matrixes encapsulates 
> Matrix *and* Vector types. I can list the Matrix and 
> Vector operations willy-nilly within this namespace.  

> In C++/Modula-3 I must list the operations on
> the private state of Matrix within the Matrix class. 
> I must list the operations on the private state of 
> Vector within the Vector class.
> There is visible association of dispatch methods and type.

I believe this is an inaccurate representation of the way Modula-3 
organizes namespaces and visibility. Much care went into designing 
namespaces and avoiding problems in the C++ "private" state model. 

Modula-3 has separate mechanisms for encapsulation (modules & 
interfaces) and inheritance and dispatching (object types). 
Using partial revelation--where one interface can reveal partial 
information about various types; others can import only the necessary 
features by importing that interface--Eric can do the kinds of 
groupings he was talking about.

Steve Freeman has written a nice article for Dr. Dobb's Journal,
comparing the encapsulation and grouping facilities of Ada95, 
C++, Eiffel, and Modula-3. He addresses precisely the kinds of issues that
Eric mentioned and goes through code examples to illustrate his
point. A copy of the article is available via the web:

http://www.research.digital.com/SRC/modula-3/html/partial-rev/index.html

Regards, -- Farshad

--
Farshad Nayeri
Critical Mass, Inc.
http://www.cmass.com/

Disclaimer: I am biased!




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

end of thread, other threads:[~1996-08-21  0:00 UTC | newest]

Thread overview: 46+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-28  0:00 Ada95 OOP Questions Spasmo
1996-07-28  0:00 ` David C. Hoos, Sr.
1996-07-28  0:00   ` Spasmo
1996-07-28  0:00 ` Andre Spiegel
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     ` Ken Garlington
1996-08-04  0:00       ` Spasmo
1996-07-30  0:00     ` David Wheeler
1996-07-31  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 I. Eachus
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-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

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