Gerard Gauthier wrote:This endorses a strict OPP view which is falling out of favor in the mainstream.
What sources do you have to support this? Who is this mainstream? What applications are they writing?
Yes you do expose the internals of the data but you have to expose something in an object for it to be accessible.
Yes, that would be accessor methods. If Java had full-fledged properties I would be 100% behind that instead, but alas, it doesn't so we need to use methods for public APIs.
The idea that its OK to expose some methods of an object while forbidding others is flawed.
Flawed how? Can you give anexplanation for this assertion?
The designer of the class has to consider its usage before committing to a public interface.
And in what use case is accessing a public field directly more appropriate than accessing it through a method? This point actually speaks against using public fields, because when I provide a method I can easily use the method handle in higher order functions, rather than having to use a lambda expression, making my code much more fluent.