On Saturday, 19 January 2013 at 00:11:03 UTC, Adam D. Ruppe wrote:
On Saturday, 19 January 2013 at 00:04:24 UTC, Andrey wrote:
So how am I supposed to hide the variable inside the struct or class?

Generally the D answer here is to put them in separate files. The module (file) is the main D encapsulation unit rather than the class/struct.

It isn't the same as C++ but I find it works pretty well - you often do one file per class anyway, and files are a natural unit for encapsulating too.

I'm sure "friend" explodes the basics of OOP encapsulation mechanics.

http://www.parashift.com/c++-faq/friends-and-encap.html

If you have helper structures it can be useful to get at the private parts anyway, for example an iteration range.

Are nested classes quite more perfectly suited for this? In my containers I implement iterator interface using nested class. Then I can easily construct mycontainer.new Iterator and have (should have by theory) access to protected (not private) members. Also I will be ensured that this is a proper iterator and that it can be constructed only when I have the instantiated parent container.

And after that D forces you to restrict access not via default language construct, but via having one declaration per file. I think this is a not correct. In OOP concept you don't have such thing as a file or module. There are no files, there is ONE program with multiple data structures and hierarchies, united under one super root. Well, at least, that is how this supposed to work from the start.

«Actually I made up the term "object-oriented", and I can tell you I did not have C++ in mind.» Alan Key.

Reply via email to