I am working on the refactoring of a Java application based on a CAST audit. One of the criteria says that
To respect the concepts of OO encapsulation, private fields must always be
accessed through accessors
So far so good. However, the audit highlights all private fields in the class that do not have mutators, regardless of how they are being used.
In my case, these fields are only accessed from within the class.
So I wonder, Is not it against the very principle of encapsulation to provide accessors for private attributes that should only be used within the classroom??
Or am I missing something more about private fields and encapsulation? Because now that I think about it, most of the IDE provides a functionality that automatically provides all the mutators for the class attributes …
EDIT: my question is not about the use of accessors within your own class. It's about the relevance of providing accessors for everyone Private fields in the class, regardless of whether they are used outside the class or not.