4 ms·
In the original JavaBeans spec, getters and setters served two purposes: 1. By declaring a getter without a setter, you could make a field read-only. 2. A set
by wtracy 8y ago
In the original JavaBeans spec, getters and setters served two purposes:
1. By declaring a getter without a setter, you could make a field read-only.
2. A setter could trigger other side effects. Specifically, the JavaBeans spec allowed for an arbitrary number of listeners to register callbacks that trigger whenever a value gets changed.
Of course, nobody actually understood or correctly implemented all this, and it all got cargo culted to hell.
- gmueckl 8y agoFinally someone mentions using getters to create read only fields. Objects are the owners and guardians of their own state. I don't see how this is possible without having (some) state-related fields that only can be read from the outside.
- pjmlp 8y agoPretty obvious to readers of "Object-Oriented Software Construction" from Meyer. A big problem is cargo culting without reading the CS references.