Sealed classes - would you want them in D?

rikki cattermole rikki at cattermole.co.nz
Thu May 10 14:48:23 UTC 2018


On 11/05/2018 2:43 AM, jmh530 wrote:
> On Thursday, 10 May 2018 at 13:47:16 UTC, rikki cattermole wrote:
>> [snip]
>>
>> Adding a keyword like sealed isn't desirable.
>>
>> I'm trying to find fault of the concept, but it definitely is tough.
>>
>> You basically want protected, but only for specific packages, 
>> otherwise final.
>>
>> protected(foo, final)
> 
> My read was that he wants an escape hatch on final so that he can extend 
> the type in a module and not have to worry about people in other modules 
> extending them.
> 
> So if he has
> 
> module foo;
> 
> class A { }
> 
> final class B : A {    }
> 
> in one module, he wants to be able to create a new
> 
> final class C : B {    }
> 
> and keep class B as final so that no one else can extend it in another 
> module.

You're right, I just didn't put it well.

My current thinking is something along the lines of:

modifier ( !|opt IdentifierList )
modifier ( !|opt IdentifierList , modifier )

Not quite correct grammar, but close enough.

So:

final(!mypackage)

would do what Piotr wants.


More information about the Digitalmars-d mailing list