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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,58bbfd2cc38993b3 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!h2g2000yqg.googlegroups.com!not-for-mail From: Gautier write-only Newsgroups: comp.lang.ada Subject: Re: 'private' and Privacy Date: Tue, 7 Jul 2009 23:51:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <843a36b0-041d-4826-98b4-0fbcb1a4d287@d9g2000prh.googlegroups.com> NNTP-Posting-Host: 206.122.158.4 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1247035869 30895 127.0.0.1 (8 Jul 2009 06:51:09 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 8 Jul 2009 06:51:09 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: h2g2000yqg.googlegroups.com; posting-host=206.122.158.4; posting-account=gRqrnQkAAAAC_02ynnhqGk1VRQlve6ZG User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/530.5 (KHTML, like Gecko) Chrome/2.0.172.33 Safari/530.5,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:6895 Date: 2009-07-07T23:51:09-07:00 List-Id: On 8 Jul., 04:48, Rick wrote: > 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. I also wondered why, until I began using it. I elaborate on your example: package Test_private_pkg is type Key_Type is private; type Keys_Type is private; procedure Define_Key(k: Key_Type; val: Integer); -- function Get_Key(k: Keys_Type; i,j: Integer) return Key_Type; procedure Set_Key(k: Keys_Type; i,j: Integer; new_val: Key_Type); private type Key_Type is new Integer; KEYPAD_ROWS_COUNT : constant Positive := 2; -- The number of rows on a keypad. KEYPAD_COLUMNS_COUNT : constant Positive := 2; -- The number of columns on a keypad. type Keys_Type is array (1 .. KEYPAD_ROWS_COUNT, 1 .. KEYPAD_COLUMNS_COUNT) of Key_Type; end; > 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. Now, with the private definitions as above, we have exactly what you need: with Test_private_pkg; use Test_private_pkg; procedure Test_private is key: Key_Type; keys: Keys_Type; i: Integer; begin Define_key(key, 123); Set_Key(keys, 1,2, key); i:= KEYPAD_ROWS_COUNT; -- You don't want the user to do that >>> test_private.adb:15:07: "KEYPAD_ROWS_COUNT" is not visible >>> test_private.adb:15:07: non-visible (private) declaration at test_private_pkg.ads:15 The reason why the private things are not hidden is that the compiler needs to know about type sizes and perhaps other details when using the private types. If you have to really hide information (passwords, software registration ID's,... ), you need to use functions, provide the specification and not the body's source code, and in the body you may even need to encrypt your stuff. But it is another topic... _________________________________________________________ Gautier's Ada programming -- http://sf.net/users/gdemont/ NB: For a direct answer, e-mail address on the Web site!