From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: constructor in abstract tagged types
Date: Wed, 8 May 2019 21:26:05 +0200
Date: 2019-05-08T21:26:05+02:00 [thread overview]
Message-ID: <qavage$4dd$1@gioia.aioe.org> (raw)
In-Reply-To: 0ca05176-a819-4e9a-8c6c-3a0c1f32f964@googlegroups.com
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
next prev parent reply other threads:[~2019-05-08 19:26 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 [this message]
2019-05-18 11:31 ` Daniel
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