comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Assigning a "subclass" instance to a "superclass" variable
Date: Fri, 06 Apr 2012 22:50:18 +0100
Date: 2012-04-06T22:50:18+01:00	[thread overview]
Message-ID: <m2ty0wh6n9.fsf@pushface.org> (raw)
In-Reply-To: jlnkt5$91i$1@dont-email.me

deuteros <deuteros@xrs.net> writes:

> I'm still trying to understand how Ada does object orientation. In
> Java I could do this:
[...]
> So in Ada I'm trying to achieve something similar with my Statement
> package: 
>
> package Statements is
>
>    type Statement is abstract tagged
>       record
>          tokens : Vector;
>          executedtokens : Vector;
>       end record;
>    
>    type Statement_Access is access all Statement'Class;
>    
>    function execute(skip: in Boolean; S: in Statement) return Integer is abstract;
>
> end Statements;
>
> So when I create a child of Statement, how to I set up the .ads file?

   with Statements;
   package Expressions is
      type Expression is new Statements.Statement with record
         ...
      end record;
      function Execute (Skip : Boolean; S : Expression) return Integer;
   end Expressions;

or

   package Statements.Expressions is
      type Expression is new Statement with record
         ...
      end record;
      function Execute (Skip : Boolean; S : Expression) return Integer;
   end Statements.Expressions;

The second form is good if the full declaration of Statement is in the
private part of Statements, since child packages can see the private
parts of their parents.



  reply	other threads:[~2012-04-06 21:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-06 20:49 Assigning a "subclass" instance to a "superclass" variable deuteros
2012-04-06 21:50 ` Simon Wright [this message]
2012-04-06 23:13   ` deuteros
2012-04-07  7:06     ` Simon Wright
2012-04-07  7:06     ` Dmitry A. Kazakov
2012-04-07  7:08     ` Niklas Holsti
2012-04-07 10:18 ` Georg Bauhaus
replies disabled

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