Post Made Community Wiki by Dale
source | link

I thought we would have more usual answers here?

Getters and setters are in general extremely OOP (anyone saying anything else are wrong, simple as that).

Though you need to remember to not over engineer, never make an getter or setter that isn't needed. Any information that you aren't going to use by another class you shouldn't have any getter or setter for.

Though, the reason why you don't make fields public and instead have getters and setters are mostly:

  • It's not possible to make proper tests by using fields. Getters/setters are much better in that regard.

  • It's impossible to properly use fields in a real time programming setting. Synchronized getters/setters is the way to go.

  • The interface topic (already explained so I won't).

  • It's easier to use when properly reusing the system.

  • It's much harder to know which classes that's using your class and what will break if you change a field than a getter/setter.

Therefor the only time you use a public field instead of an getter/setter is when you don't make an official project but instead just doing it for fun and can't bother with the getter/setters.