how to make private class member private

psychoticRabbit meagain at meagain.com
Tue Mar 13 08:32:54 UTC 2018


On Tuesday, 13 March 2018 at 08:05:43 UTC, psychoticRabbit wrote:
> On Tuesday, 13 March 2018 at 06:03:11 UTC, Mike Parker wrote:
>>
>> I think it's a great feature and I use it frequently. It's 
>> allows more flexibility in class design. Without it, we'd need 
>> another protection attribute to enable the concept of "private 
>> to the module".
>>
>
> what about a new access attribute (and no, I haven't though 
> this through much):
>
> owned string _FirstName;
>
> (now the class 'owns' this.
>
> It is neither readable nor writeable outside the boundary of 
> that class.
>
> This retains the existing flexibilty offered by module level 
> encapsulation, while restoring class level 
> encapsulation/ownership.

or another idea:

ownedBy T string _FirstName;

where T could be 'Module' (meaning it works the way it currently 
does. The module can read/write to it).

or T could 'Universe' (where universe means everyone can do 
whatever they want with it).

or T could be 'This'(so class can regain control overs its own 
members),

The default could be ownedBy Module, to retain existing behaviour.

I'd even go further, with extended attributes...

ownedBy Module Read string _FirstName;
ownedBy Module Write string _FirstName;
ownedBy Module ReadWrite string _FirstName;




More information about the Digitalmars-d-learn mailing list