
Why getter and setter methods are evil - raju
http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1
======
gamble
What I find more insidious is the way accessor methods naturally encourage you
to treat them as if they are performance-equivalent with member variables.
People will reference them in loops, blithely unaware that they're building
and rebuilding the same data structures in accessors that are only
superficially similar to member variables.

~~~
delackner
What do you do to avoid this? I try to name my heavy-lifting methods so that
they do not look like simple accessors, but sometimes it is inevitable.

For instance, a large dataset may have a method to get the length of the
dataset. If the dataset does not maintain a member variable that has that
value, then you have to calculate it. Later, for performance, you might
implement an ivar that is updated whenever the dataset changes, thus making
the method a simple accessor.

~~~
gamble
If something walks and quacks like a member variable, I'm happy to make it a
member variable. Otherwise, it gets to be a function.

(Obviously this doesn't apply in languages like ObjC or C++ where accessors
are often necessary for memory management)

------
jwilliams
Jump to page 6 and read the summary :
[http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbo...](http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=6)

The rest of the article has some interesting points, but I found it too wordy.

