Link Details

Link 87390 thumbnail
User 1 avatar

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.
  • 14
  • 18
  • 2244
  • 1246

Comments

Add your comment
User 285418 avatar

Motion Control replied ago:

1 votes Vote down Vote up Reply

So, lets ditch JavaBeans "the component architecture for the Java 2 Platform".

User 233461 avatar

antych replied ago:

1 votes Vote down Vote up Reply

If only more people would understand this...

User 102928 avatar

dglasser replied ago:

1 votes Vote down Vote up Reply

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.

User 283139 avatar

ceaseoleo replied ago:

0 votes Vote down Vote up Reply

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.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.