From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Full view of a private partial view cannot be a subtype Date: Mon, 4 Dec 2017 09:25:00 +0100 Organization: Aioe.org NNTP Server Message-ID: References: <889a3aed-4e6b-49c8-8c1c-6f1478e8e077@googlegroups.com> NNTP-Posting-Host: MyFhHs417jM9AgzRpXn7yg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 X-Notice: Filtered by postfilter v. 0.8.2 Content-Language: en-US Xref: reader02.eternal-september.org comp.lang.ada:49342 Date: 2017-12-04T09:25:00+01:00 List-Id: 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 ; 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