3 ms·
I think it's partly a defensive tactic to stop others playing fast and loose with your object state. I used to write classes and then add fields and auto gener
by jiggy2011 14y ago
I think it's partly a defensive tactic to stop others playing fast and loose with your object state.
I used to write classes and then add fields and auto generate getters/setters.
Now I don't, I just make all the state private and if I find myself wanting a getter/setter I ask myself why.
Too much use of getters/setters is just reinventing the problem that private state was meant to avoid.
So for example rather than:
if(email.getState() == EmailState.SENT) {
I have:
if(email.wasItSent()) {
- edwinnathaniel 14y agoWhat if a 3rd-party API only works on Beans? (i.e. doesn't support private properties).