From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ucbvax!eg.ti.COM!FMOORE From: FMOORE@eg.ti.COM.UUCP Newsgroups: comp.lang.ada Subject: Design issue: Generics vs Private types Message-ID: <8705270150.AA06260@ucbvax.Berkeley.EDU> Date: Tue, 26-May-87 18:09:00 EDT Article-I.D.: ucbvax.8705270150.AA06260 Posted: Tue May 26 18:09:00 1987 Date-Received: Thu, 28-May-87 01:49:08 EDT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: world Organization: The ARPA Internet List-Id: 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