4 ms·
I seem to recall the whole getter/setter thing becoming popular with JavaBeans (note not EJBs). Java didn't have a nice way of identify something as a "property
by arethuza 16y ago
I seem to recall the whole getter/setter thing becoming popular with JavaBeans (note not EJBs). Java didn't have a nice way of identify something as a "property" that could be exposed graphically through an IDE interface so adopted a syntactic convention. This soon became adopted as "best practice" even though I suspect 99.9% of getters and setters do nothing but expose an underlying field - as with most programming "best practices" very few people can actually tell you what the benefits are supposed to be.
- prodigal_erik 16y agoThe sad thing is all JavaBeans needed was named arguments to the constructor rather than relying on setter names. It's a lot more complicated for every class to let instances be created in a mostly-uninitialized state, relying on a bunch of setter calls in an unspecified order to make the instance actually usable. For one thing, there's no language-supported way to make a setter mandatory, you can't do any better than blowing up at runtime if it wasn't called.
- artsrc 16y agoSpring prefers setters and getters (the constructor support is not as good), and this makes it harder to communicate what is optional configuration with defaults and what is essential.