3 ms·
> 1. Members marked private being accessible from other instances of the same class [1] is counter to every other OO language I have used. What is the prior art
by JoshTriplett 9y ago
> 1. Members marked private being accessible from other instances of the same class [1] is counter to every other OO language I have used. What is the prior art here? Why depart from all conventions like this?
C++ works that way, and several other languages do as well. And the use case mentioned in that comment is exactly the reason: the implementation of a class knows how to access both its own private fields and those of another instance of itself, so that it can do comparisons, combinations, or other operations.
- spankalee 9y agoIt gets really tricky when you have any kind of polymorphism, intended or not. If you accept instances of your own class as arguments to a method, you may be templated to think you can access the private fields of those arguments, even if instanceof checks pass, but they may not be there.
- deleted 9y ago[deleted]