Hacker News new | ask | show | jobs
by wtracy 2613 days 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.

1 comments

Finally 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.
Pretty obvious to readers of "Object-Oriented Software Construction" from Meyer.

A big problem is cargo culting without reading the CS references.