Extending D's support for object-oriented design with private(this)
Lance Bachmeier
no at spam.net
Thu Apr 25 12:55:33 UTC 2024
On Thursday, 25 April 2024 at 05:37:24 UTC, NotYouAgain wrote:
> Both (1) (2) (3) can be fully resolved by adding private(this)
> functionality, as demonstrated here:
>
> // --
> module m;
>
> class C
> {
> private(this) int _count; // visibilty of this member is
> contained within this type
> }
>
> unittest
> {
> C c = new C();
> c._count = 42; // Error: data member _count is an
> inaccessible (private)property of type `m.C`
> }
>
> // ----
This introduces a more restricted version of private. Overloading
`private` to give it a second meaning is going to cause confusion
for new users and really anyone that doesn't use D's OOP all the
time. I recommend using something like `hidden` or
`strongprivate`.
More information about the dip.ideas
mailing list