Why Getters & Setters Aren't OOP, Use This Technic Instead
How Yegor Bugayenko's concept of printers finally achieve proper OOP encapsulation
Getters and Setters are common practice but fundamentally against OOP.
Allen Holub describes how getters and setters make your code terrible for maintainability. He also states that this overall pattern of using getters and setters is questionable. OOP is all about encapsulation and not revealing inner logic to outer spaces. Guess what? Use getters, and you do exactly spread internals out.
With revealing instead of encapsulating, you create highly dependent parts.
The OOP concept indeed says not to reveal internals, but how is it even possible to work internal data?
1. Getters & Setters Talk Too Much…
An easy start with a class of a CD
with two fields of _name
and _band
. These internals are sealed and can't be accessed from the outside.