Getters are Meh?

  • "Getter" methods may be bad
  • public void getSomething() {
      return this.something;
    }
  • Do consumers of your object need to see the data you're storing?
  • Can you use the result of a computation right away? Should somebody else store it?
  • Getters are ok in data transfer objects in Java
  • Occasionally useful elsewhere but can be a crutch

9 / 22