comp.lang.ada
 help / color / mirror / Atom feed
From: FMOORE@eg.ti.COM.UUCP
Subject: Design issue: Generics vs Private types
Date: Tue, 26-May-87 18:09:00 EDT	[thread overview]
Date: Tue May 26 18:09:00 1987
Message-ID: <8705270150.AA06260@ucbvax.Berkeley.EDU> (raw)

When should generic packages be used to encapsulate data as
opposed to using packages with private data types?

Consider the following two approachs to protecting data:


generic                              ! package COUNTER is
package COUNTER_TYPE is              ! type C_T is private;
   procedure ZERO;                   !   procedure ZERO (ITEM : out C_T);
   procedure INCREMENT;              !   procedure INCREMENT (ITEM : in out
   procedure DISPLAY;                !                          C_T);
end COUNTER_TYPE;                    !   procedure DISPLAY (ITEM : in C_T);
                                     ! private
package body COUNTER_TYPE is         !   type C_T is some_type ...
DATUM : some_type ...                !  -- data hidden as private type
...-- data hidden within body        ! end COUNTER;
end COUNTER_TYPE;                    !
                                     !
package COUNTER1 is new COUNTER_TYPE;! COUNT1, COUNT2 : COUNTER.C_T;
package COUNTER2 is new COUNTER_TYPE;!
                                     !
COUNTER1.ZERO;                       ! COUNTER.ZERO (COUNT1);
COUNTER2.ZERO;                       ! COUNTER.ZERO (COUNT2);
                         etc.        !


I can imagine that the implementation of these two approaches would
vary from compiler to compiler, especially depending upon how a
compiler implements generics.

However, my interest is in expressing designs.  From the point of
view of good design technique, can one approach over the other be
supported?  If so, what design technique / rules are involved?

Thanks for any insight.
Freeman Moore
FMOORE%ti-eg@relay.cs.net

             reply	other threads:[~1987-05-26 22:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-05-26 22:09 FMOORE [this message]
1987-05-29 13:40 ` Design issue: Generics vs Private types Arny B. Engelson
1987-05-30  6:58   ` Doug Bryan
replies disabled

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