Providing getter and setter method for public variable is fine. It gives following advantages:
- Centralized control for accessing varibales
- Gives chance to programmer for validations before setting the value.
But for private fields if we provide getters and setters then that variable is no longer private. Doesn't it breaks encapsulation principle? Could you please explain the real advantage of using getters and setters for private members? Or is it something which we all are using blindly?
I read many blogs but could not get convincing reason for having getters and setters for private variables.