3 ms·
The language design failure that get/set methods are used to monkey patch around is the lack of computed properties. If you have an object with properties A an
by OkayPhysicist 4y ago
The language design failure that get/set methods are used to monkey patch around is the lack of computed properties.
If you have an object with properties A and B, but later realize that B can be calculated from A, it would be nice to eliminate the class of "Inconsistent A and B Values" bugs from your software, by making B calculated from the value of A. The problem is, without computed properties, that involves replacing the Object.B expressions with Object.getB() expressions, breaking your API.
So Java developers got in the habit of putting getters and setters on everything.
- marginalia_nu 4y agoI don't think that rationale makes a lick of sense in code written today. Besides the obvious violation of the YAGNI-principle and stinky mixture of data and logic, even if this scenario arises (which it very rarely does) any Java IDE worth its salt can replace a variable access with a method with a few mouse clicks. Now, in 1995, maybe...
- ivanche 4y agoThat is very broad generalization. I have a habit of never writing them unless I'm forced to do it.