CodeSOD: The Set Up

This post was originally published on this site

The Daily WTF

My heretical opinion on object-oriented programming is that I don’t like getters and setters. They’re often trivial boilerplate (boilerplate is a code smell), or they’re hiding behavior where behavior probably doesn’t belong.

Yes, yes, I understand the importance of encapsulation, but in a lot of ways, trivial getters/setters break encapsulation. void setFoo(T foo) { this.foo = foo; } does nothing to protect foo against unauthorized modifications.

So while I understand encapsulation, I don’t think I understand it as well as the Senior Engineer responsible for today’s anonymous submission. Because they certainly fixed the encapsulation issues with setters:

public void setStatus() { this.status = status; }

This Java setter method guarantees that I can’t alter the status property of this object to an incorrect value, because I can’t alter it at all. status and this.status are referring to the same value.

Our anonymous submitter adds:

IDE tooling showed that

To read the full article click on the 'post' link at the top.