how to make private class member private

psychoticRabbit meagain at meagain.com
Tue Mar 13 06:25:24 UTC 2018


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".

That's kind of my point. That's what I would have done, if for no 
other reason, to prevent the same syntax from having different 
semantics (when C++/C#/Java programmers come over to D).

And I switch between them all, and now, I have to remember D's 
private memeber is something very different indeed.

> In Java, it's recommended to manipulate private member 
> variables through their accessors even in methods of the same 
> class. I've always found that extreme.

Java is extreme in many ways ;-)

but at least, private member, is still a private member (to the 
class).

If my private class memeber can be directly modified outside of 
the class, then class encapsulation IS broken. Just saying, oh 
no, it's module encapsulation you should be thinking about, seems 
kinda strange, since we still use classes - which are their own 
level of encapsulation. That's the whole point of them.




More information about the Digitalmars-d-learn mailing list