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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,12a63150f4f961a,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.68.231.2 with SMTP id tc2mr2014015pbc.8.1336080475958; Thu, 03 May 2012 14:27:55 -0700 (PDT) Path: pr3ni654pbb.0!nntp.google.com!news1.google.com!goblin1!goblin.stu.neva.ru!feed.xsnews.nl!border-3.ams.xsnews.nl!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!news.online.de!not-for-mail From: Felix Krause Newsgroups: comp.lang.ada Subject: OOP in Ada: Alternatives for "protected" scope Date: Thu, 3 May 2012 23:27:55 +0200 Organization: 1&1 Internet AG Message-ID: NNTP-Posting-Host: port-92-203-9-240.dynamic.qsc.de Mime-Version: 1.0 X-Trace: online.de 1336080475 11083 92.203.9.240 (3 May 2012 21:27:55 GMT) X-Complaints-To: abuse@einsundeins.com NNTP-Posting-Date: Thu, 3 May 2012 21:27:55 +0000 (UTC) User-Agent: Unison/2.1.7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Date: 2012-05-03T23:27:55+02:00 List-Id: Hi all, I have used Ada's OOP-features for quite some time now, and there is one thing that really bothers me: Ada does not provide any class-based visibility scopes. In some cases, the package-based approach to visibility / information hiding just doesn't seem to provide enough flexibility. Let me give an example: I have some abstract class A, defined in package P_A. This class provides some functionality as procedure Do_Something. Now there is some calculation to be done while execution Do_Something which cannot be defined in A. Therefore, it is left to the specific child classes of abstract class A to implement that calculation. The code might look like this: package P_A is type A is abstract tagged private; procedure Do_Something (Object : in out A); function Calculate (Object : in out A) return Integer is abstract; private -- define A here... end P_A; package body P_A is procedure Do_Something (Object : in out A) is Var : Integer; begin -- some useful code hereā€¦ -- let the specific child class define this calculation Var := Calculate (Object); -- some more useful code here... end Do_Something; end P_A; The function Calculate should only be used internally. I do not see a good way to enforce this with Ada: I do not want to move it to P_A's private part, because child classes of A should not be required to be located in sub-packages of P_A. (It's also forbidden for an abstract function to reside in the private part.) In languages like Java and C#, there is a "protected" scope to cope with this situation. Now of course these languages, unlike Ada, are based on OOP, so it is natural for them to provide class-based visibility scopes. My question is, how would one implement this kind of visibility in Ada?