From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: troubles learning OOP: expected type "Parent.Some_Child", found type Parent'Class
Date: Tue, 13 Feb 2018 18:56:09 +0100
Date: 2018-02-13T18:56:09+01:00 [thread overview]
Message-ID: <p5v8rp$1bec$1@gioia.aioe.org> (raw)
In-Reply-To: p5v81j$2el$1@dont-email.me
On 2018-02-13 18:42, Jeffrey R. Carter wrote:
> On 02/12/2018 10:18 PM, Mehdi Saada wrote:
>>
>> I can't believe T_TOKEN'class is as useless... well, in a sense, since
>> the program doesn't know the actual type of TOKEN but only that it's a
>> child of T_TOKEN, no wonder there's some limitations. But I'm
>> surprised there's no mechanism in the language, to tell the program:
>> HEY there ! I'm sure it's T_TOKEN_OPERANDE, so now consider TOKEN as
>> such and let me reach it's OPERANDE component.
>
> Given an object V of T_Token'Class, you can do
>
> if V in T_Token_Operateur
>
> and
>
> if V in T_Token_Operateur'Class
>
> and then do a conversion to access the components of the extension. You
> can also compare V'Tag to the tags of the derived types. All of these
> are frowned on as "not the type-extension way" by aficionados of type
> extension.
Right. It is bad to expose type-specific components. This why Ada offers
type S is new T with private;
to ensure that clients cannot access internals of the type otherwise
than through public operations which normally should be operations
defined on the whole class and thus accessible through dispatch without
any type conversions and explicit tests.
P.S. There are few cases when Ada design fails and there is a need to
convert away from the root type. E.g. in class-wide construction
functions when a specific object is returned as a class-wide. The
pattern is to create a result and then convert to the specific type to
initialize.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2018-02-13 17:56 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-12 16:29 troubles learning OOP: expected type "Parent.Some_Child", found type Parent'Class Mehdi Saada
2018-02-12 17:44 ` Jeffrey R. Carter
2018-02-12 18:17 ` Mehdi Saada
2018-02-12 18:24 ` Dmitry A. Kazakov
2018-02-12 18:42 ` Simon Wright
2018-02-12 20:25 ` Jeffrey R. Carter
2018-02-12 21:18 ` Mehdi Saada
2018-02-12 22:40 ` Simon Wright
2018-02-12 23:12 ` Mehdi Saada
2018-02-13 8:00 ` Stephen Leake
2018-02-13 17:42 ` Jeffrey R. Carter
2018-02-13 17:56 ` Dmitry A. Kazakov [this message]
2018-02-12 21:19 ` Mehdi Saada
2018-02-12 18:40 ` Simon Wright
2018-02-12 21:39 ` Mehdi Saada
2018-02-12 21:43 ` Mehdi Saada
2018-02-12 22:22 ` Mehdi Saada
2018-02-13 17:46 ` Jeffrey R. Carter
2018-02-13 20:19 ` Mehdi Saada
2018-02-13 21:24 ` Bojan Bozovic
2018-02-13 23:03 ` Mehdi Saada
2018-02-13 23:03 ` Mehdi Saada
2018-02-14 7:00 ` Bojan Bozovic
2018-02-14 12:04 ` Mehdi Saada
2018-02-16 23:40 ` Mehdi Saada
2018-02-17 1:13 ` Mehdi Saada
2018-02-13 0:01 ` Mehdi Saada
2018-02-13 0:42 ` Mehdi Saada
2018-02-13 1:32 ` Mehdi Saada
2018-02-13 4:16 ` Bojan Bozovic
2018-02-13 11:28 ` Simon Wright
2018-02-13 12:03 ` Mehdi Saada
2018-02-13 13:25 ` Dmitry A. Kazakov
2018-02-19 18:10 ` Mehdi Saada
2018-02-19 18:16 ` Simon Clubley
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox