comp.lang.ada
 help / color / mirror / Atom feed
From: ldries46 <bertus.dries@planet.nl>
To: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Using Generic Pasckages
Date: Thu, 9 Apr 2020 12:05:37 +0200
Date: 2020-04-09T12:05:37+02:00	[thread overview]
Message-ID: <fca3b4d4-bfb8-596f-682d-ec13b185c520@planet.nl> (raw)
In-Reply-To: <r6mo17$1cj5$1@gioia.aioe.org>

Op 9-4-2020 om 10:57 schreef Dmitry A. Kazakov:
> On 2020-04-09 10:40, ldries46 wrote:
>> I have created some generic packages. tese are packages that only do 
>> the same thing but with other types. Till now I did only need these 
>> packages without interaction with between packages using the same 
>> type. I just can declare them:
>> Package AA is new BB(type); then calling them as
>> A := AA.Get_Value;
>> No other declaration seemed to be neccesary .
>>
>> Now I have the following situation:
>> Package AA is new BB(integer);
>> Package CC is new BB(integer);
>> and a case where I have several statements using Package AA in one 
>> condition and CC the other case.
>> I want  to do that by using:
>> if D then EE := AA; else EE := CC; end if;
>> But I cannot find in the documentation  how the declaration of EE 
>> should be made.
>>
>> Of course there is the possibility to create the same progrram 
>> without using EE but that is far less readable and thus creating more 
>> possible errors.
>>
>> If I have to do this without the generic packages I already have the 
>> program alse will be less readable.
>
> What you are observing is the advantages of dynamic polymorphism 
> (tagged types) over the static one (generics).
>
> Already the name static hints that you cannot select a polymorphic 
> implementation (AA or CC) using some non-static (dynamic) expression D.
>
I am using Generic because in the program the same routines should be 
possible for several different types, but now I have also a situation 
where two instantiations of the same type should be used under some 
conditions. For instance in a instantiation of a buffer of 
Unbounded.String's depending on the condition one of two should be used, 
but the buffer should also be used for another type

  reply	other threads:[~2020-04-09 10:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09  8:40 Using Generic Pasckages ldries46
2020-04-09  8:57 ` Dmitry A. Kazakov
2020-04-09 10:05   ` ldries46 [this message]
2020-04-09 11:23     ` Dmitry A. Kazakov
2020-04-09 15:38 ` AdaMagica
2020-04-09 18:23 ` Simon Wright
2020-04-09 20:45 ` Jere
2020-04-10 16:34 ` Stephen Leake
2020-04-11 13:16   ` ldries46
2020-04-11 14:15     ` Jeffrey R. Carter
replies disabled

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