I would like to know, your opinion about the use of getters and setters in several languages as PHP, C#, JavaScript, etc. It's a good way to encapsulate behaviors, validations?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (2)
Getters and setters work well when updating the object at the property level is what you want. For instance when you manipulate ORM generated data transfer objects.
But for 'domain objects' I think there's an advantage to have a dedicated method with a meaningful name for any modification to the entity. The method may even return a Failed result or raise an Exception.
A typical example could be a bank account. The rules for adding / withdrawing may be very different whereas they both manipulate the balance.
Thank you for detailed response! I definitely agree with you!