comp.lang.ada
 help / color / mirror / Atom feed
From: "Bennett, Chip (KTR) ~U" <BennettC@J64.STRATCOM.AF.MIL>
Subject: Re: don't understand packages vs. objects/classes
Date: Tue, 29 Nov 1994 09:04:00 PST
Date: 1994-11-29T09:04:00-08:00	[thread overview]
Message-ID: <2EDB5E6E@SMTPGATE2.STRATCOM.AF.MIL> (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              *
*****************************************************************



             reply	other threads:[~1994-11-29 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-11-29 17:04 Bennett, Chip (KTR) ~U [this message]
  -- strict thread matches above, loose matches on Subject: below --
1994-11-27  4:42 don't understand packages vs. objects/classes 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
replies disabled

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