comp.lang.ada
 help / color / mirror / Atom feed
* Ada 2005 OOP : newbie questions
@ 2011-01-27 14:54 Bill Findlay
  2011-01-27 15:15 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ messages in thread
From: Bill Findlay @ 2011-01-27 14:54 UTC (permalink / raw)


I have a package P that declares

   type R is new Limited_Controlled with private;

The private extension of R contains a number of fields that I want to be
common to future derived types S, T, etc; P declares a number of primitive
operation signatures of R that I want S, T, etc, to override; and there are
some operations on R'Class in P as well.

1. Can I prevent objects of type P.R from being declared,
   while allowing objects of types S, T, etc?

2. Can I prevent a useless primitive of P.R, say P.Op from being called?
   At the moment the body of P.Op raises an exception, but I would much
   prefer to have a compile-time check (of course).

I feel sure that there is a general way of dealing with such issues,
but at the moment I can't seem to see the wood for the trees.

-- 
Bill Findlay
with blueyonder.co.uk;
use  surname & forename;




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ada 2005 OOP : newbie questions
  2011-01-27 14:54 Ada 2005 OOP : newbie questions Bill Findlay
@ 2011-01-27 15:15 ` Dmitry A. Kazakov
  2011-01-27 15:50   ` Bill Findlay
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2011-01-27 15:15 UTC (permalink / raw)


On Thu, 27 Jan 2011 14:54:01 +0000, Bill Findlay wrote:

> I have a package P that declares
> 
>    type R is new Limited_Controlled with private;
> 
> The private extension of R contains a number of fields that I want to be
> common to future derived types S, T, etc; P declares a number of primitive
> operation signatures of R that I want S, T, etc, to override; and there are
> some operations on R'Class in P as well.
> 
> 1. Can I prevent objects of type P.R from being declared,
>    while allowing objects of types S, T, etc?

A type with no instances is abstract:

   type R is abstract new Limited_Controlled with private;

> 2. Can I prevent a useless primitive of P.R, say P.Op from being called?

Useless in which sense? If the operation cannot be implemented in R, it
should be abstract to be implemented in S and T.

   procedure Foo (Object : in out R) is abstract;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Ada 2005 OOP : newbie questions
  2011-01-27 15:15 ` Dmitry A. Kazakov
@ 2011-01-27 15:50   ` Bill Findlay
  0 siblings, 0 replies; 3+ messages in thread
From: Bill Findlay @ 2011-01-27 15:50 UTC (permalink / raw)


On 27/01/2011 15:15, in article rahmct77kd97$.1st3durl551z$.dlg@40tude.net,
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote:

> On Thu, 27 Jan 2011 14:54:01 +0000, Bill Findlay wrote:
> 
>> I have a package P that declares
>> 
>>    type R is new Limited_Controlled with private;
>> 
>> The private extension of R contains a number of fields that I want to be
>> common to future derived types S, T, etc; P declares a number of primitive
>> operation signatures of R that I want S, T, etc, to override; and there are
>> some operations on R'Class in P as well.
>> 
>> 1. Can I prevent objects of type P.R from being declared,
>>    while allowing objects of types S, T, etc?
> 
> A type with no instances is abstract:
> 
>    type R is abstract new Limited_Controlled with private;

D'oh! I KNEW that (once)! Thanks for the reminder, Dmitry!

-- 
Bill Findlay
with blueyonder.co.uk;
use  surname & forename;





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-01-27 15:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-27 14:54 Ada 2005 OOP : newbie questions Bill Findlay
2011-01-27 15:15 ` Dmitry A. Kazakov
2011-01-27 15:50   ` Bill Findlay

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