comp.lang.ada
 help / color / mirror / Atom feed
* Re: don't understand packages vs. objects/classes
@ 1994-11-29 17:04 Bennett, Chip (KTR) ~U
  0 siblings, 0 replies; 5+ messages in thread
From: Bennett, Chip (KTR) ~U @ 1994-11-29 17:04 UTC (permalink / raw)


"Andrew E. Caldwell" <caldwell@TYPHOON.SEAS.UCLA.EDU> wrote:

> It seems to me (in my VERY limited Ada knowledge) that packages are
> like classes for OOP purposes.  They have the features of data hiding, and
> binding procedures with data, hiding implementation, etc. But, how
> do you get more than one of them in a procedure/function.

I'm having a hard time understanding why we are compelled to keep giving you
generics as the solution to your question.  It's sort of like using an
elephant gun to kill an ant.  It seemed to me that your question had more to
do with how to get many stacks, not how to get stacks of different types.

If you're only implementing stacks of integers, you need only declare a
abstract stack type that is instantiated a number of times (for each stack),
and managed by the push and pop routines in the same package.  A possible
spec would be:

     package IntStacks is

        type Stack is private;

        procedure Push (S : in out Stack; Item : in Integer);

        function Pop (S : in out Stack) return Integer;

     private

        type Stack is ...  -- actual representation
                           -- i.e. array of integers,
                           --      linked list of integers, etc.

     end Stacks;

You might use this stack type in the following way:

     with IntStacks; use IntStacks;
     procedure YourProg is
        Stack1 : Stack;
        Stack2 : Stack;
     begin
        Push (Stack1, 34);
        Push (Stack2, 12);
     end YourProg;

Generics is a beautiful concept, way ahead of its time in 1983, but we
sometimes have a tendency to use them in every answer.  They give a great
deal of flexibility, but are not needed in every solution.

*****************************************************************
* Chip Bennett, GDE Systems Inc | BennettC@j64.stratcom.af.mil  *
* USSTRATCOM/J64213             | Voice (402)294-7360           *
* 901 SAC Blvd, Suite 2B24      | FAX   (402)294-7912           *
* Offutt AFB, NE 68113-6600     | Proud member of Team Ada      *
* Opinions expressed here are my own _so_,  TTFWTW              *
*****************************************************************



^ permalink raw reply	[flat|nested] 5+ messages in thread
* don't understand packages vs. objects/classes
@ 1994-11-27  4:42 Andrew E. Caldwell
  1994-11-27 14:58 ` Roger Labbe
  1994-11-28 15:02 ` Mark C. Chu-Carroll
  0 siblings, 2 replies; 5+ messages in thread
From: Andrew E. Caldwell @ 1994-11-27  4:42 UTC (permalink / raw)


Could someone please help me understand this.  Either there is a large
group of syntactic constructs I missed in the manual, or I am
still stuck in c++/smalltalk mode, or I just don't get it.

It seems to me (in my VERY limited Ada knowledge) that packages are 
like classes for OOP purposes.  They have the features of data hiding, and
binding procedures with data, hiding implementation, etc. But, how
do you get more than one of them in a procedure/function.

For instance, if I define the package STACK to have the procedures
POP which returns say, an integer, and PUSH(X:integer), and I want
to use my STACK in a procedure, I do something like (please, although my
Ada style may not be the usual as I'm new, I think it's clear what I'm asking,
so...)

with STACK;
procedure foo is
use stack;
test:integer;

begin
--a procedure body
end foo;

and inside foo I can call test = POP;
and this works.  But, what if foo needed TWO stacks, or three? As STACK
doesn't appear to be named, it doesn't look like an object.  It's a 
support library, rather than a data type?  But, that wasn't what I 
thought it was supposed to be.  If it is just a library of functions,
then does Ada have a class/object structre?  How about all the OOP
subjects I've  seen on this list lately- surely it must.

-andy		caldwell@seas.ucla.edu




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

end of thread, other threads:[~1994-11-29 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-11-29 17:04 don't understand packages vs. objects/classes Bennett, Chip (KTR) ~U
  -- strict thread matches above, loose matches on Subject: below --
1994-11-27  4:42 Andrew E. Caldwell
1994-11-27 14:58 ` Roger Labbe
1994-11-28 11:35   ` David Weller
1994-11-28 15:02 ` Mark C. Chu-Carroll

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