3 ms·
I'm not sure this excludes the use of getters and setters under any and all circumstances. A purist argument is that objects are supposed to do stuff, and that
by andrewf 18y ago
I'm not sure this excludes the use of getters and setters under any and all circumstances.
A purist argument is that objects are supposed to do stuff, and that methods should be big, chunky verbs that don't expose unnecessary implementation details - including dozens of properties and twiddly knobs that "could be useful some day".
But if you're building container classes for a model, then your value of "do stuff" is "store data and make it available to others", so the use of getters and setters seems entirely reasonable.
- ajross 18y agoAgreed. This article seems like a good idea (essentially: "don't write needless code", and "don't expose fine-grained stuff you don't have to") extended to the point of pedantry. Certainly accessor methods can be clean and useful, especially for things like computed or read-only values. They certainly aren't a red flag for maintainability by themselves.