4 ms·
The typical argument for getters/setters is that there is some logic that should be performed and that's why the fields should not be public. If there's logic,
by JustSomeNobody 9y ago
The typical argument for getters/setters is that there is some logic that should be performed and that's why the fields should not be public. If there's logic, they should be tested. If there's no logic, they should be public fields.
- taeric 9y agoSee my sibling response. The files were tested. There just wasn't a "testGetter" method in our tests.
- twblalock 9y agoNo, the point of getters and setters is that the interface to get and set fields should be the same whether or not logic is being performed behind the scenes, and the caller should not need to know. Making fields public makes it impossible to add logic in the future without changing other code. That breaks encapsulation and is generally non-idiomatic in languages with getters and setters.