Re:Data Classes for Java
by mohaine on Wednesday November 01, 2017 @07:43PM
(#15606549)
Getters/Setters do have a couple of reasons to exist:
1) Allowing you to validate data/morph data on your objects on set. (example: Date is not a workday)
2) Allow others to do either 1 or other actions on set/get (examples: Hibernate entity beans that update db/set dirty on set, GUI can extend object to update on set)
That said it was a total PITA when this first became popular. I spent way too much time changing code over because that was now "best practice". And don't get me started on Boolean not being get but is or has.
1) Allowing you to validate data/morph data on your objects on set. (example: Date is not a workday)
2) Allow others to do either 1 or other actions on set/get (examples: Hibernate entity beans that update db/set dirty on set, GUI can extend object to update on set)
That said it was a total PITA when this first became popular. I spent way too much time changing code over because that was now "best practice". And don't get me started on Boolean not being get but is or has.