comp.lang.ada
 help / color / mirror / Atom feed
From: Matthew J Heaney <mheaney@on2.com>
Subject: Re: Limiting inheritance
Date: 2000/07/27
Date: 2000-07-27T00:00:00+00:00	[thread overview]
Message-ID: <7rk8e7b4dj.fsf@butter.albany.duck.com> (raw)
In-Reply-To: 8lq7tj$5rt$1@nnrp1.deja.com

reason67@my-deja.com writes:

> package Patch is
> 
>    type Patch_Type is (red, orange, yellow, green, blue, violet);
> 
>    subtype Base_Patch_Type is Patch_Type Red .. Green;
> 
>     type Object is tagged private;
> 
>     ...
> 
>     procedure Set_Patch_Kind (To : in Base_Patch_Type; In_Object : in
> Object);

[snip]
 
> package Patch.Fancy is
> 
>     subtype Fancy_Patch_Kind is Patch_Kind Blue .. Violet;
> 
>     type Object is new Patch.Object with tagged private;
> 
> ...
> 
>     procedure Set_Patch_Kind (To : in Fancy_Patch_Type; In_Object : in
> Object);



> I can make the procedres 2 different names but if I go that route, I
> want to NOT inherit the procedure from the parent to the child. Is
> there a way to do this?

If you don't want the derived type to inherit the operation from its
parent, then it sounds like the (parent) operation shouldn't be
primitive for the type.

If so, there are few things you can do:

1) Declare the operation as a class-wide operation:

package Patch is
   ...
   procedure Set_Patch_Kind (... In_Object : in Object'Class);
   ...
end Patch;

Of course, this operation is now "class"-wide, meaning that it can be
used for any type in the class, including fancy-patch objects.  This may
or may not be what you want.


2) You can declare the operation as a non-class-wide, non-primitive
   operation, by either 

2a) declaring it as a child subprogram:

package Patch is 
...
end Patch;

procedure Patch.Set_Patch_Kind (... In_Object : in Object);


2b) declaring it in a nested package:

package Patch is
   ...
   package Nonprimitive is
      procedure Set_Patch_Kind (... In_Object : in Object);
   end;

   procedure Set_Patch_Kind (...) renames --legal?
      Nonprimitive.Set_Patch_Kind; 

   ...
end Patch;

In both 2a) or 2b) the operation takes only objects of exactly type
Patch.Object.




  reply	other threads:[~2000-07-27  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-07-27  0:00 Limiting inheritance reason67
2000-07-27  0:00 ` Matthew J Heaney [this message]
2000-07-28  0:00   ` Ehud Lamm
2000-07-29  0:00 ` Robert I. Eachus
replies disabled

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