From: Daniel Norber <danielnorberto@gmail.com>
Subject: Mixing public and private member of a class. Dealing with what to hide and not
Date: Wed, 13 Feb 2019 09:40:21 -0800 (PST)
Date: 2019-02-13T09:40:21-08:00 [thread overview]
Message-ID: <5e42642d-3dd4-4c53-8b24-50bde70485f8@googlegroups.com> (raw)
Sorry for my bad english.
I'm having big troubles in how Ada deals mixing public and private member of a class.
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 example massaging service and making pizzas service. Every services goes in a differente child package, but i will focus just in massaging service package.
I had two approaches. One trying to build classes in the same package and i always get "premature
derivation of derived or private type", so i will explain how i try using differents tagged in different packages paradigm.
As i understood, the only way to mix public and private members is declaring 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_but_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) return 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);
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 like "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 internal use . In the same way this whole class has private parts like "changemysecrets" not available for the outer world.
Any help or ideas of how to do it? (if it possible respecting 1 "with" dependency in the outter world side)
Thank you very much and Best regards.
next reply other threads:[~2019-02-13 17:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-13 17:40 Daniel Norber [this message]
2019-02-13 17:46 ` Mixing public and private member of a class. Dealing with what to hide and not Daniel
2019-02-13 20:05 ` Dmitry A. Kazakov
2019-02-13 20:39 ` J-P. Rosen
2019-02-14 0:21 ` Jere
2019-02-14 18:04 ` G.B.
2019-02-22 8:42 ` Daniel
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox