Are setter methods only used to set the value of attributes as it is passed as argument? Can we write some validation logic before assigning the value to the attributes?
It is actually encouraged to validate the input (check whether it fits your data abstraction) to your setter method, so yes you can.