comp.lang.ada
 help / color / mirror / Atom feed
* Design issue: Generics vs Private types
@ 1987-05-26 22:09 FMOORE
  1987-05-29 13:40 ` Arny B. Engelson
  0 siblings, 1 reply; 3+ messages in thread
From: FMOORE @ 1987-05-26 22:09 UTC (permalink / 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

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

end of thread, other threads:[~1987-05-30  6:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1987-05-26 22:09 Design issue: Generics vs Private types FMOORE
1987-05-29 13:40 ` Arny B. Engelson
1987-05-30  6:58   ` Doug Bryan

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