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=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a37:4b93:: with SMTP id y141mr6776993qka.205.1579639906406; Tue, 21 Jan 2020 12:51:46 -0800 (PST) X-Received: by 2002:a9d:24ea:: with SMTP id z97mr5031511ota.345.1579639906011; Tue, 21 Jan 2020 12:51:46 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!g89no8434753qtd.0!news-out.google.com!w29ni2115qtc.0!nntp.google.com!g89no8434746qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 21 Jan 2020 12:51:45 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <6dbb0da9-8c68-435e-945d-d0e1eefeda4c@googlegroups.com> Subject: Re: Calling a record type's methods (functions or procedure) when record is in an array From: Shark8 Injection-Date: Tue, 21 Jan 2020 20:51:46 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57910 Date: 2020-01-21T12:51:45-08:00 List-Id: On Saturday, January 18, 2020 at 11:02:32 AM UTC-7, Mace Ayres wrote: >=20 > In your code below with my mark up =E2=80=9C * ?=E2=80=9D, are the sub p= rograms private in any way since they are below Type Thing is private, or t= he privacy is applied to Thing? Ada has a concept called private types, "TYPE X IS PRIVATE;", where the typ= e's implementation is hidden from the clients of the package. Thus you coul= d have the following: Package Example is Type Point is private; =20 -- Getters: Function X( Object : in Point ) return Integer; Function Y( Object : in Point ) return Integer; =20 -- Setters: Procedure X( Object : in out Point; Value : in Integer ); Procedure Y( Object : in out Point; Value : in Integer ); Private =20 Type Point is record X_Value, Y_Value : -- Integer; Real; End record; End Example; Package Body Example is Function X( Object : in Point ) return Integer is Begin Return Integer(Object.X_Value); End X; =20 Procedure X( Object : in out Point; Value : in Integer ) Begin Object.X_Value:=3D Real( Value ); End X; Function Y( Object : in Point ) return Integer is Begin Return Integer(Object.Y_Value); End Y; =20 Procedure Y( Object : in out Point; Value : in Integer ) is Begin Object.Y_Value:=3D Real( Value ); End Y; End Example; And now, you could change the type of the components to Point to Integer, r= emove the type-casts, and recompile the package Example **without having to= recompile dependent packages** because they are dependent only on the visi= ble portion of the package. >=20 > That is, what is the full scope of privacy in declaring type thing as pri= vate, to type thing only, or the sub programs too. Or is this a confused q= uestion anyway? See above. Private types are Ada's method of hiding implementation-details. For exampl= e, you could have a Password type that, internally, is a string but none of= the package-clients can see that: Package Other_Example is Min_Length : Constant Natural; Function Valid_Characters( Input : String ) return Boolean; =20 Type Password(<>) is private; =20 =20 Function Create( Input : String ) return Password with Pre =3D> Valid_Characters(Input) and Input'Length >=3D Min_Length; Function "=3D"( Left, Right : Password ) return Boolean; Function "=3D"( Object : Password; Value : String ) return Boolean; =20 Private =20 -- A Password must be at least 5 characters, -- and may contain only alphanumeric characters. Min_Length : Constant Natural:=3D 5; Function Valid_Characters( Input : String ) return Boolean is (for all C of Password =3D> C in 'a'..'z'|'A'..'Z'|'0'..'9'); =20 Type Password is new String with Dynamic_Predicate =3D> Password'Length >=3D Min_Length and then Valid_Characters( String(Password) ); =20 Function Create( Input : String ) return Password is ( Password(Input) ); End Other_Example;