5

Setter and getter are anti-patterns. Eradicate all of them from your code with no mercy and you'll see your code magically transform for the better.

Comments
  • 2
    Well it's not the *worst*
  • 1
    I've heard this before too. What's the explanation behind it?
  • 1
    Can you elaborate on this topic please?
  • 1
  • 2
    Short answer: www.yegor256.com

    Long answer: Getters/setters supposedly make your classes/objects less OO. Since most will tend to over-abuse them and turn all of their classes into "dumb" databags. OO dictates that any data should not be exposed to anyone. You ought to expose only the flow of logic/interaction of objects but never more.

    While that sounds nice and all, actually trying to stand by those values in the real world translates to pure pain. Workable for small projects, borderline impossible for bigger ones.
Add Comment