Sealed classes - would you want them in D?
bachmeier
no at spam.net
Tue May 15 14:34:07 UTC 2018
On Saturday, 12 May 2018 at 06:35:55 UTC, KingJoffrey wrote:
> Come on, your code example misses my point completely.
>
> Take this program below, for example, and tell me that class
> encapsulation is not broken in D:
>
> ===============================
> module test;
>
> import std.stdio : writeln;
>
> void main()
> {
> Person p = new Person("King Joffrey");
>
> writeln(p.getName); // I designed my class to return this.
> writeln(p._name); // But D can bypass your intention
> completely.
>
> p._name = "New King"; // even worse, D can nominate another
> king.
> writeln(p._name);
> }
I think I'm missing something. Why is it a problem that you can
do this? How do other languages prevent you from doing it?
More information about the Digitalmars-d
mailing list