4 ms·
I think getters/setters are an abomination resulting from a sensible OO idea taken too far. Having private fields and public methods has benefits that are so o
by geophile 9y ago
I think getters/setters are an abomination resulting from a sensible OO idea taken too far.
Having private fields and public methods has benefits that are so obvious that I won't belabor the point. Sometimes -- maybe even often -- you really do want to get and set some fields, so then you have getters and setters. But applying this pattern blindly, to all fields, is insane and, as many people on this thread have noted, defeat the point of private fields and public methods. Just make the fields public, because that's how much protection you have anyway. (Adding code around the getting and setting is, of course, easier with methods already in place.)
I think this trend really got started with Java Beans, in which getters/setters were required (unless you wanted to write yet more code to nominate other methods as the getters and setters). And then the stupidity set in. Well why wouldn't you want your object to be a bean? Beans are good! Be a bean.
I believe that things like corporate coding standards then kicked in and made this nonsense unavoidable.
- platz 9y agojust use a struct for plain data