comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Assigning a "subclass" instance to a "superclass" variable
Date: Sat, 7 Apr 2012 09:06:14 +0200
Date: 2012-04-07T09:06:14+02:00	[thread overview]
Message-ID: <ke2cltl51m1g$.1mcrh0ryuisj0$.dlg@40tude.net> (raw)
In-Reply-To: jlntb4$pm8$1@dont-email.me

On Fri, 6 Apr 2012 23:13:40 +0000 (UTC), deuteros wrote:

> I want something like a constructor in my child classes:
> 
>     	function Create_Expression (tokens, executedtokens : Vector) return Expression is
>     	    	E : Expression
>     	begin
>     	    	E.tokens := tokens;
>     	    	E.executedtokens := executedtokens;
>     	    	return E;
>     	end Create_Expression;
> 
> Now if the Expression package must have its own tokens and executedtokens
> I assume this would be the way to do it but if not then how would this
> work?

Then the parent type (Statement) should not have them in its
implementation. If children have token types of their own (a parallel types
hierarchy), you should provide an abstract interface to access
child-specific tokens. E.g.

   function Get_Token (S : Statement; Index : Token_Index_Type)
      return Token_Type'Class is abstract;

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



  parent reply	other threads:[~2012-04-07  7:06 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
2012-04-06 23:13   ` deuteros
2012-04-07  7:06     ` Simon Wright
2012-04-07  7:06     ` Dmitry A. Kazakov [this message]
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