Extending D's support for object-oriented design with private(this)
NotYouAgain
NotYouAgain at gmail.com
Sat Apr 27 12:52:33 UTC 2024
On Saturday, 27 April 2024 at 12:45:27 UTC, Kagamin wrote:
> Javascript doesn't indicate much, it had no protection at all.
ok sure. how about almost every other major language in use then.
but back to D...
class ClassWithPrivateField
{
private int privateField; // actually, my intent here is
private(this),
// but it cannot be expressed in D.
// guess I better put the subclass in
its own module
// in the hope that someone thinks by
doing that,
// I've expressed that intent.
this() { this.privateField = 42; }
}
class Subclass : ClassWithPrivateField
{
private int subPrivateField;
this()
{
this.subPrivateField = 23;
this.privateField = 52; // is this a mistake? The compiler
has no way to know.
}
}
More information about the dip.ideas
mailing list