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: 103376,b8b8a54001adc4d2 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!c13g2000cwb.googlegroups.com!not-for-mail From: danmcleran@hotmail.com Newsgroups: comp.lang.ada Subject: Re: Possible Ada deficiency? Date: 1 Jan 2005 15:28:10 -0800 Organization: http://groups.google.com Message-ID: <1104622090.271236.286730@c13g2000cwb.googlegroups.com> References: <1104516913.718856.94090@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 172.154.140.252 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1104622094 8611 127.0.0.1 (1 Jan 2005 23:28:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 1 Jan 2005 23:28:14 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: c13g2000cwb.googlegroups.com; posting-host=172.154.140.252; posting-account=LSix6gsAAACmBFWMCbh6syCaua0lawvj Xref: g2news1.google.com comp.lang.ada:7380 Date: 2005-01-01T15:28:10-08:00 List-Id: Here's a different way to illustrate this problem. If I want to extend a type, I can do this with a non-child package. But, if I make the package containing the extended type a child package, I then have access to all of the private area as well. So, one can extend a type with or without access to the private area, depending on whether one makes the packages containing the derived type a child package or not. In my example, notice that the derived type in the child package can change the private area, whereas the derived type in the non-child package cannot. Consider these files (Main.adb is the test program): --Some_Package.ads package Some_Package is type Secret_Type is tagged private; procedure Print_Secret_Value (Value : in out Secret_Type'Class); private type Secret_Type is tagged record Secret_Value : Integer := 0; end record; end Some_Package; --Some_Package.adb with Ada.Text_IO; package body Some_Package is procedure Print_Secret_Value (Value : in out Secret_Type'Class) is begin Ada.Text_IO.Put_Line (Item => "Secret value = " & Integer'Image(Value.Secret_Value)); end Print_Secret_Value; end Some_Package; --Some_Package.Child_Package.ads package Some_Package.Child_Package is type Some_Child_Type is new Secret_Type with null record; procedure Badness ( Child : in out Some_Child_Type; New_Value : in Integer); end Some_Package.Child_Package; --Some_Package.Child_Package.adb package body Some_Package.Child_Package is procedure Badness ( Child : in out Some_Child_Type; New_Value : in Integer) is begin Child.Secret_Value := New_Value; end Badness; end Some_Package.Child_Package; --Non_Child_Package.ads with Some_Package; package Non_Child_Package is type Derived_Type is new Some_Package.Secret_Type with null record; procedure Badness ( Derived : in out Derived_Type; New_Value : in Integer); end Non_Child_Package; --Non_Child_Package.adb package body Non_Child_Package is procedure Badness ( Derived : in out Derived_Type; New_Value : in Integer) is begin --Derived.Secret_Value := New_Value;--won't compile null; end Badness; end Non_Child_Package; --Main.adb with Some_Package; with Some_Package.Child_Package; with Non_Child_Package; procedure Main is Child_Value : Some_Package.Child_Package.Some_Child_Type; Non_Child : Non_Child_Package.Derived_Type; begin Some_Package.Print_Secret_Value (Value => Child_Value); Some_Package.Print_Secret_Value (Value => Non_Child); Some_Package.Child_Package.Badness (Child => Child_Value, New_Value => 100); Non_Child_Package.Badness (Derived => Non_Child, New_Value => 100); Some_Package.Print_Secret_Value (Value => Child_Value); Some_Package.Print_Secret_Value (Value => Non_Child); end Main;