Sealed classes - would you want them in D? (v2)
Gheorghe Gabriel
knoppy273 at live.com
Fri May 18 12:00:58 UTC 2018
On Thursday, 17 May 2018 at 02:32:07 UTC, KingJoffrey wrote:
> I propose an idea, for discussion (robust discussion even
> better ;-)
>
> Add an new attribute to class, named 'sealed'.
>
> No, not sealed as in Scala.
>
> No, not sealed as in C#
>
> sealed as in oxford dictionary (close securely, non-porous).
>
> when sealed is applied on the class, this means the class is
> sealed.
>
> the sealed attribute only makes sense within a module, and
> affects nothing outside of the module.
>
> When sealed is applied to the class, then, interfacing to a
> class within a module, from code outside that class - but still
> within the module, can now only occur via the published
> interface of the class.
>
> outside code in the module, can no longer directly access your
> private parts!
>
> The class is sealed.
I think this code has cleaner sintax:
class A {
private int x;
sealed int y;
}
void main() {
A a = new A();
a.x = 7; // ok, it's private to module
a.y = 3; // error, it's sealed to class
}
More information about the Digitalmars-d
mailing list