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:a24:ac5b:: with SMTP id m27mr1026817iti.12.1550079622579; Wed, 13 Feb 2019 09:40:22 -0800 (PST) X-Received: by 2002:aca:cf4f:: with SMTP id f76mr25900oig.7.1550079622088; Wed, 13 Feb 2019 09:40:22 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!u65no167ita.0!news-out.google.com!2ni106itx.0!nntp.google.com!u127no1690ita.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 13 Feb 2019 09:40:21 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2a01:c50e:ac00:b900:b50f:cbc7:686:3b6; posting-account=C8J7NQoAAAD_ybGY7--QIRi6KpLjoH1Z NNTP-Posting-Host: 2a01:c50e:ac00:b900:b50f:cbc7:686:3b6 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5e42642d-3dd4-4c53-8b24-50bde70485f8@googlegroups.com> Subject: Mixing public and private member of a class. Dealing with what to hide and not From: Daniel Norber Injection-Date: Wed, 13 Feb 2019 17:40:22 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:55508 Date: 2019-02-13T09:40:21-08:00 List-Id: Sorry for my bad english. I'm having big troubles in how Ada deals mixing public and private member o= f a class.=20 Please someone can help how to do it using Ada ? Im building lets say a library, where i choose to use classes (tagged types= ) for interfacing with the outer world. This library is organized in services using ada packages. Lets say my Library is called SERVICES and it has differents parts, for exa= mple massaging service and making pizzas service. Every services goes in a = differente child package, but i will focus just in massaging service packag= e. I had two approaches. One trying to build classes in the same package and i= always get "premature=20 derivation of derived or private type", so i will explain how i try using d= ifferents tagged in different packages paradigm. As i understood, the only way to mix public and private members is declarin= g the public part and make a child with private; Here is my code: package SERVICES is pragma PURE; end SERVICES; -having 1 dependency with my internal code: with REGISTERING_STUFF; package SERVICES.MASSAGES is type dont_instance_me_bcs_im_not_full_but_public is record Register : REGISTERING_STUFF.notebook; end record type instance_bcs_im_the_good is new dont_instance_me_bcs_im_not_full_bu= t_public with private; --public part for the outer world: procedure makeme_a_massage_in_public (S: instance_bcs_im_the_good); function Say_in_public_if_its_painfull(S:instance_bcs_im_the_good) retur= n boolean; private --private part for my massaging related code type instance_me_bcs_im_the_good is new dont_instance_me_bcs_im_not_full= with record more_secret_data : natural; end record; procedure changemysecrets (S: instance_me_bcs_im_the_good); end SERVICES.MASSAGES; package REGISTERING_STUFF is type notebook is tagged limited private; function whoami (S: notebook) return String; private type notebook is tagged record private_secret_data : natural; end record; procedure takecarechangingnotes (S: notebook ;data: String);=20 end REGISTERING_STUFF; So from a client to the library, i try this: --The client only Have 1 dependency with my library with SERVICES.MASSAGES; package client body is interface_class : SERVICES.MASSAGES.instance_me_bcs_im_the_good; begin ada.text_io.Put_Line(interface_class.Register.whoami); end client; I have the next error running client: >error no selector whoami for private type notebook I want one and simple class that includes everything to the outer world lik= e "instance_me_bcs_im_the_good" that expose the public part like procedure = "makeme_a_massage_in_public", and also the public part of "notebook" like "= whoami" function, but hidding for example takecarechangingnotes just for in= ternal use . In the same way this whole class has private parts like "chang= emysecrets" not available for the outer world. Any help or ideas of how to do it? (if it possible respecting 1 "with" depe= ndency in the outter world side) Thank you very much and Best regards.