comp.lang.ada
 help / color / mirror / Atom feed
From: Felix Krause <flyx@isobeef.org>
Subject: OOP in Ada: Alternatives for "protected" scope
Date: Thu, 3 May 2012 23:27:55 +0200
Date: 2012-05-03T23:27:55+02:00	[thread overview]
Message-ID: <jnut8r$aqb$1@online.de> (raw)

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?




             reply	other threads:[~2012-05-03 21:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-03 21:27 Felix Krause [this message]
2012-05-03 21:56 ` OOP in Ada: Alternatives for "protected" scope Dmitry A. Kazakov
2012-05-04 18:48   ` Felix Krause
2012-05-04 22:00     ` Dmitry A. Kazakov
2012-05-05  8:28       ` Felix Krause
2012-05-05 11:53         ` Dmitry A. Kazakov
2012-05-05  4:33     ` Shark8
2012-05-03 23:34 ` Randy Brukardt
2012-05-04  1:41 ` BrianG
2012-05-04 10:37 ` Georg Bauhaus
2012-05-04 10:43   ` Georg Bauhaus
2012-05-04 12:10   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox