Mar 8, 2021
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.