3 ms·
Not only are getters/setters not necessary, they actively work against good object orientation. The whole point of OO was to work with things in terms of their
by tedyoung 6y ago
Not only are getters/setters not necessary, they actively work against good object orientation. The whole point of OO was to work with things in terms of their _behavior_ and not their _data_. The way OO is taught by creating data-centric classes has misled generations of developers into thinking they understand encapsulation by making a variable private and then providing a getter & setter for it.
I spend a good part of my time training Java developers away from this idea in order to help them make their code more testable and understandable. Queries and Commands are not just pedantic alternate names for Getters and Setters: thinking about objects with respect to what you can ask it to do (Command or Request) and what you can find out from it (Query) significantly improves the code that gets written.