By rick
via typicalprogrammer.com
Published: Jun 15 2008 / 09:30
Every getter and setter in your code represents a failure to encapsulate and creates unnecessary coupling. A profusion of getters and setters (also referred to as accessors, accessor methods, and properties) is a sign of a poorly-designed set of classes.



Comments
Motion Control replied ago:
So, lets ditch JavaBeans "the component architecture for the Java 2 Platform".
antych replied ago:
If only more people would understand this...
dglasser replied ago:
The author of this piece is a moron. Someone asked him in the comments:
"Say you needed to populate a listbox with the names of you customers (Customer being the object with a member variable Name). How would you code this so that you don’t use a getter?”
and his response was:
"Implement a Customer method addNameToList(listbox). The listbox object passed in would need a method to add a single name, so Customer::addNameToList(listbox) would in turn call listbox.add(this.Name)."
So now, a class designed to hold simple data is coupled to UI classes. How stupid is that? And I suppose you would need a different "addNameToXXX" method for each UI component out there. All because he claims a customer class should not have a getName() method.
ceaseoleo replied ago:
voted up just for the discussion value, where as controlling scope is always a necessary, and in the point of less is more, accessors should not just automatically be created, using the ide is a good and bad thing.
Voters For This Link (14)
Voters Against This Link (18)