comp.lang.ada
 help / color / mirror / Atom feed
From: Daniel <danielnorberto@gmail.com>
Subject: Re: constructor in abstract tagged types
Date: Sat, 18 May 2019 04:31:30 -0700 (PDT)
Date: 2019-05-18T04:31:30-07:00	[thread overview]
Message-ID: <a3cc39ec-b9da-482d-948f-4d6103898e7f@googlegroups.com> (raw)
In-Reply-To: <qavage$4dd$1@gioia.aioe.org>

El miércoles, 8 de mayo de 2019, 21:26:10 (UTC+2), Dmitry A. Kazakov  escribió:
> On 2019-05-08 20:37, Daniel wrote:
> 
> > Hello, im trying to know how can i use abstract tagged types and constructors at the same time.
> 
> Ada does not have proper constructors. But there are various software 
> patterns to work this around.
> 
> > I have this
> > 
> > package FATHERS is
> >    type Father is abstract tagged record
> >       Years : Natural;
> >       field1 : Natural;
> > --    .....and 15 more fields
> >    end record;
> > 
> >    function F_build(Years :Natural) return Father is abstract;
> >    procedure F_forced_to_do_it is abstract;
> 
> private
>     --
>     -- Class-wide initialization of Father's fields
>     --
>     procedure Initialize (Object : in out Father'Class; Years : Natural);
> 
> > end FATHERS;
> > 
> > package FATHERS.SONS is
> > type Son is new father with record
> >     skate : boolean;
> > end Son;
> > 
> > function F_Build(Years :Natural) return Son;
> > procedure F_Forced_to_do_it;
> > end FATHERS.SONS;
> > 
> > package body FATHERS.SONS is
> > 
> > function F_Build(Years : Natural) return Son is
> > begin
>       return Result : Son do
>          Initialize (Result, Years); -- Parent's "constructor"
>          Result.Skate := True;
>       end return;
> > end F_Build;
> > 
> > end FATHERS.SONS;
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thank you Dmitry. It really works for me!


  reply	other threads:[~2019-05-18 11:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-08 18:37 constructor in abstract tagged types Daniel
2019-05-08 19:26 ` Dmitry A. Kazakov
2019-05-18 11:31   ` Daniel [this message]
2019-05-08 20:50 ` Jere
2019-05-10 22:35   ` Randy Brukardt
2019-05-09 14:40 ` AdaMagica
2019-05-10  4:46   ` Petter Fryklund
2019-05-18 11:35   ` Daniel
2019-05-10 22:40 ` Randy Brukardt
2019-05-18 11:43   ` Daniel
replies disabled

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