TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Date:
Thu, 20 May 1999 10:33:15 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (82 lines)
Christoph & Ursula Grein wrote:
>
> What is the difference between declaring overriding operations in the visible
> part and declaring them in the private part?

If you override in the private part, it has no effect outside the
package if the type is untagged.  If the type is tagged, overriding
in the private part is pretty much the same as overriding in the
visible part.  However, you have no opportunity to
change (visibly) the formal parameter names or the default
parameter expressions.

-Tuck

>
> Consider the following example:
> ----------------
> package Class is
>
>   type Root is tagged null record;
>
>   procedure Operation (R : in Root);
>
>   type Derived is new Root with null record;
>
>   -- procedure Operation (D : in Derived);  -- overrides
>
> private
>
>   procedure Operation (D : in Derived);  -- overrides
>
> end Class;
> -----------------
> with Ada.Text_Io;
> use  Ada.Text_Io;
>
> package body Class is
>
>   procedure Operation (R : in Root) is
>   begin
>     Put_Line ("Root");
>   end Operation;
>
>   procedure Operation (D : in Derived) is
>   begin
>     Put_Line ("Derived");
>   end Operation;
>
> end Class;
> -----------------
> with Class;
> use  Class;
>
> procedure Tester is
>
>   R : Root;
>   D : Derived;
>
> begin
>
>   -- no dispatching calls
>   Operation (R);  -- visible
>   Operation (D);  -- derived, invisibly overridden
>
> end Tester;
> -------------------
> The specific operation for object Derived is inherited and invisibly overridden.
>
> Why does this work? What is the difference to overriding it in the visible part?
> Please enlighten me.
>
> Christoph Grein
> Member of Ada Germany
>
> http://home.T-Online.de/home/Christ-Usch.Grein
> [log in to unmask]

--
-Tucker Taft   [log in to unmask]   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA

ATOM RSS1 RSS2