From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Full view of a private partial view cannot be a subtype
Date: Mon, 4 Dec 2017 09:25:00 +0100
Date: 2017-12-04T09:25:00+01:00 [thread overview]
Message-ID: <p030os$1g8k$1@gioia.aioe.org> (raw)
In-Reply-To: dd1b71a7-9bfb-4f7c-8109-bb06f54505b4@googlegroups.com
On 03/12/2017 23:23, Jere wrote:
> Well, I think either form is a bit too polar. I've always been taught that
> you use the tool that makes the most sense given the context. If a type
> has an "is a" relationship, you favor extension. But if it has a "has a"
> relationship, you favor composition. If the situation is unique enough,
> then you do something outside the norm.
These two are confusing. One is subtyping another is aggregation.
In your "is-a" the right part is a type or a class of types. E.g. X is a
Integer = the type of X is a subtype of Integer or, alternatively,
member of Integer'Class.
In your "has-a" the right part is a container, like String has
Character. The left and right are unrelated types.
Now there is a "has-a" related to subtyping. Ada does not have that. It
is a supertype. E.g. if you could declare an interface Numeric and hang
it on an existing type Integer:
type Number is old Integer; -- (:-))
or
supertype Number is Integer <wider range, other numbers>;
Numeric has an Integer = Integer is a Numeric.
Then extension is irrelevant to either "is-a" or "has-a" subtyping
relation. It is an implementation detail regarding representations of
two related types. You could have "is-a" with, without extension or
completely abandoning another type representation, but not in Ada. Ada
glues interface and representation together. That was an unfortunate
design choice motivated by premature optimization in order to have view
conversions.
> In this case I wasn't using extension because I thought it was the best
> method. I was using it because Ada doesn't provide me a good way to
> rename a type as part of the full view. Normally I would use subtype,
> but I can't do that with a private declaration (I don't want the client
> to have access to the "subtypedness", but I want to leverage it under
> the hood). Extension was my first stab at it because of the natural
> flow of type declarations in Ada.
Ada's subtype is another method to implement "is-a"/"has-a"
relationships by borrowing representation and putting constraints. It is
"is-a" for in-parameters, "has-a" for out-parameters. It is neither
worse or better than extension, it is different.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
next prev parent reply other threads:[~2017-12-04 8:25 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-03 2:14 Full view of a private partial view cannot be a subtype Jere
2017-12-03 12:01 ` Jeffrey R. Carter
2017-12-03 13:33 ` Jere
2017-12-03 14:34 ` Jeffrey R. Carter
2017-12-03 17:44 ` Robert Eachus
2017-12-03 18:50 ` Simon Wright
2017-12-03 22:10 ` Robert Eachus
2017-12-03 19:03 ` Jeffrey R. Carter
2017-12-03 22:23 ` Jere
2017-12-04 8:25 ` Dmitry A. Kazakov [this message]
2017-12-04 18:04 ` Jeffrey R. Carter
2017-12-04 20:41 ` Jere
2017-12-04 21:48 ` Jeffrey R. Carter
2017-12-05 8:20 ` Dmitry A. Kazakov
2017-12-05 18:16 ` Jeffrey R. Carter
2017-12-05 20:39 ` Dmitry A. Kazakov
2017-12-05 21:38 ` Jeffrey R. Carter
2017-12-05 12:35 ` Jere
2017-12-05 18:40 ` Jeffrey R. Carter
2017-12-06 12:54 ` Jere
2017-12-06 18:03 ` Jeffrey R. Carter
2017-12-05 20:22 ` Randy Brukardt
2017-12-05 15:27 ` Shark8
2017-12-05 18:50 ` Jeffrey R. Carter
2017-12-05 20:59 ` Randy Brukardt
2017-12-05 22:43 ` Shark8
2017-12-07 0:52 ` Randy Brukardt
2017-12-05 20:16 ` Randy Brukardt
2017-12-05 21:29 ` Jeffrey R. Carter
2017-12-07 0:04 ` Randy Brukardt
2017-12-04 20:49 ` Randy Brukardt
2017-12-05 12:56 ` Jere
2017-12-05 20:12 ` Randy Brukardt
2017-12-17 15:26 ` Jere
2017-12-17 15:39 ` Dmitry A. Kazakov
2017-12-18 22:47 ` Randy Brukardt
2017-12-19 1:22 ` Jere
2017-12-19 23:16 ` Randy Brukardt
2017-12-19 1:01 ` Jere
2017-12-19 9:08 ` Dmitry A. Kazakov
2017-12-19 13:08 ` Jere
2017-12-19 13:27 ` Dmitry A. Kazakov
2017-12-19 19:10 ` Stephen Leake
2017-12-18 20:45 ` Stephen Leake
2017-12-18 22:54 ` Randy Brukardt
2017-12-19 1:08 ` Jere
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox