Setters should perform some kind of validation, otherwise you might just as well not restrict access to the pertinent field.

However, setters are not required, and in some cases should not be provided at all. For example, a bank account object should not allow arbitrary changes to its balance field. Instead, it should receive an immutable transaction object.

It should go without saying that immutable classes shouldn't have setters.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store