Could somebody please provide an example where getters and setters are not required?
I still do not get the idea, I guess a very huge class with lots of attributes must have them but in simpler cases?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Getters and setters have a number of related purposes:
All of these add up to a convincing argument for using setters and getters everywhere.
To my mind, there is only two cases where getters and setters are “optional”:
private.In these cases, the reasons for using getter and setters mostly don’t apply. In particular, since the visibility of the attributes and their types are restricted to the enclosing class, the ripple effect of changing them is limited to the source code file that defines the class.
However, if there is a risk that the inner classes implementation details will leak in a revision of the code, you should immediately add getters and setters.