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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!g31g2000yqc.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: 'private' and Privacy Date: Wed, 8 Jul 2009 05:47:39 -0700 (PDT) Organization: http://groups.google.com Message-ID: <2e6bb81a-6e74-4198-abb4-33b584931e9f@g31g2000yqc.googlegroups.com> References: <843a36b0-041d-4826-98b4-0fbcb1a4d287@d9g2000prh.googlegroups.com> NNTP-Posting-Host: 88.170.86.208 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1247057259 6118 127.0.0.1 (8 Jul 2009 12:47:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 8 Jul 2009 12:47:39 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g31g2000yqc.googlegroups.com; posting-host=88.170.86.208; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061208 Iceweasel/3.0.9 (Debian-3.0.9-1),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6903 Date: 2009-07-08T05:47:39-07:00 List-Id: Rick Duley wrote on comp.lang.ada: > I have never fathomed out why we declare entities in packages to be > 'private' and then have to go and tell the world what is in them. =A0I > would assume that 'private' has something to do with 'information > hiding' yet we expose what is 'private'. Because the compiler needs to know the sizes of all types and objects so it can emit the code for passing parameters to the subprograms declared in the package. Ada is designed in such a way that all the information is in the spec, so the compiler needs not look at the body. This in turn makes it possible to provide only the specs and not the source files for the body. > I have: > > =A0 =A0KEYPAD_ROWS_COUNT : constant Positive :=3D 2; > =A0 =A0-- The number of rows on a keypad. > > =A0 =A0KEYPAD_COLUMNS_COUNT : constant Positive :=3D 2; > =A0 =A0-- The number of columns on a keypad. > > =A0 =A0type Keys_Type is array > =A0 =A0 =A0(1 .. KEYPAD_ROWS_COUNT, 1 .. KEYPAD_COLUMNS_COUNT) > =A0 =A0of Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; > =A0 =A0--Intermediate, addressable storage of keys for the keypad. > > I am trying to find a way to ensure that the user only addresses items > in the array in the manner I provide rather than making use of the > information clearly visible about the range of the array. =A0I can use > functions instead of constants to define array range values but they > have to be fully declared before I define the array - and this exposes > that which I wish to remain private (the actual range). > > Isn't this a contradiction in terms, or _is_ there a way to retain > 'Privacy'? It seems to me that you have a design problem. On the one hand, you expose to the client the fact that you model your widget with an array of buttons; on the other hand you don't want your client to know the bounds of the array. I think there is a contradiction inherent in this design. You can resolve the contradiction in two ways: 1) expose the array type and allow the client to index into the array directly. Prevent out-of-bounds indexes with strong typing: package Keypad is ROWS_COUNT : constant :=3D 2; COLUMNS_COUNT : constant :=3D 2; type Row_Index is range 1 .. ROWS_COUNT; type Column_Index is range 1 .. COLUMNS_COUNT; type Keys_Type is array (Row_Index, Column_Index) of Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; end Keypad; 2) provide only an abstract data type where the only operations are in terms of the semantics of each button; hide the fact that there is an array behind the scenes. If there is only one keypad, this is a singleton, so you don't even need any type declaration in the spec: with Gtk.Key_Button_Pkg; package Keypad is function First_Button return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; function Second_Button return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; function Third_Button return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; function Fourth_Button return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; end Keypad; package body Keypad is ROWS_COUNT : constant :=3D 2; COLUMNS_COUNT : constant :=3D 2; type Row_Index is range 1 .. ROWS_COUNT; type Column_Index is range 1 .. COLUMNS_COUNT; Button : array (Row_Index, Column_Index) of Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; function First_Button return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access is begin return Button (1, 1); end First_Button; -- etc. end Keypad; (if there are several keypads, you declare an abstract data type as usual: type Keypad_Type (<>) is limited private; function Construct return Keypad_Type; function First_Button (KP : Keypad_Type) return Gtk.Key_Button_Pkg.Gtk_Key_Button_Access; -- etc. ) HTH -- Ludovic Brenta.