Rethink OOP access permissions

Daniel N no at public.email
Sun Apr 28 07:30:13 UTC 2024


On Sunday, 28 April 2024 at 02:43:21 UTC, NotYouAgain wrote:
> On Saturday, 27 April 2024 at 09:25:13 UTC, Daniel N wrote:
>> This is an alternative to "private(this)".
>> ..
>
> How would your alterative compare to private(this) in the code 
> below?
>
> class ClassWithPrivateField
> {
>   private int privateField; // actually, I really wanted to do 
> 'private(this)' here.
>   this() { this.privateField = 42;  }
> }
>
> class Subclass : ClassWithPrivateField
> {
>   private int subPrivateField;
>
>   this()
>   {
>     this.subPrivateField = 23;
>     this.privateField = 52; // mmm .. this may or may not be a 
> mistake.
>                             // without private(this) you cannot 
> know.
>                             // you could use convention, but we 
> all know
>                             // how well that scales ;-)
>   }
> }

I'm the first to admit the syntax of my proposal needs work, but 
I just wanted to get the discussion going.

```d
get(class) set(class) int privateField; // equivalent with 
private(this)
```

By solving more than one usecase, the feature might appeal to 
more people.





More information about the dip.ideas mailing list