DEV Community

Discussion on: Do we really need getters/setters?

Collapse
 
andsmile profile image
Andrii

What I see in code in 99% of cases, private fields and lombok getters/setters, and I don't see any benefits of 'encapsulation' here, literally no encapsulation.

Collapse
 
mateuszjarzyna profile image
Mateusz Jarzyna

But serialization frameworks requires that convention. Hibernate/Jacson and other are looking for methods that starts with get/is/set to read or set the value.

Thread Thread
 
andsmile profile image
Andrii

As I know Hibernate does not always need getters.
But it is good point.

Collapse
 
awwsmm profile image
Andrew (he/him)

Private fields with getters and setters that do nothing other than get and set are totally pointless, you're right. It's the ability to interrupt the user's command and do something else before getting or before or after setting that makes them useful.