[External] : Re: Possible refinement for sealed classes
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Apr 1 20:25:09 UTC 2021
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Jeudi 1 Avril 2021 16:27:55
> Objet: Re: [External] : Re: Possible refinement for sealed classes
>>> Essentially, I want to put the `permits` list on Sandwich, and have `WithCheese`
>>> and friends delegate their permits to `Sandwich`, rather than having each
>>> interface enumerate their subtypes.
>> I'm not sure to understand why this case is special enough to get a special way
>> of delegating the "sealness" (the fact to be sealed, i don't know if there is a
>> term in English for that) apart that it would be cool to have it.
> The tradeoff of sealing is that you have to maintain an explicit list of
> permitted subtypes (unless you're lucky enough that your whole hierarchy fits
> in one file.) That's fine, but if you program in the Sandwich style outlined in
> this thread (which is a reasonable style for modeling some domains), you end up
> having to write O(n) permits lists, and keep them in sync. This is annoying for
> both code writers and readers; gunking up the declaration of WithCheese (which
> is a pretty abstract concept) with a list of concrete cheese-bearing sandwiches
> feels out of place.
I don't like too much the whole traits/mixins ideas because you share the implementation and the type at the same time, it's the same issue with inheritance, usually at some points you will discover that you don't want both.
By example, a type WithCheese may make little sense.
Anyway, if WithCheese only makes sense for a Sandwich, nesting WithCheese inside Sandwich is the way to go.
>> Delegating the "sealness" in that direction, from an interface which subtypes
>> are subtypes to the sealed type, seems less readable that the other direction,
>> from the sealed type to the interface that will have subtypes that implement
>> the sealed type.
> Sure, there's other ways to paint the shed, but the concept here is: WithCheese
> only makes sense in the context of Sandwich (according to this sandwich
> restaurant.) This is the concept we're trying to capture; it could be at the
> declaration of the interface, or at the declaration of Sandwich.
As i said above, make WithCheese a nested interface of Sandwich, it shows that WithCheese only makes sense in the context of of Sandwich and you get permitted subtypes inference as a bonus.
I believe that sealed traits in scale are restricted to the same compilation unit too.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20210401/b7baec93/attachment.htm>
More information about the amber-spec-experts
mailing list