Something I've been thinking about....
For a class that has instance variables, I tend to use private variables and
getter/setter methods for access. In the
class itself, however, I'm wondering which makes sense, to use the
getter/setters within the class itself, *or* to
access the variables directly. I guess I'm sort of torn because I can make a
case for each method. Obviously, using
the getter/setters creates additional overhead *but* using them within the
class seems to be more roboust.
Additionally, I tend to consider creating a generic method to add a certain
functionality, then create methods that
overload by adding (or removing) parameters.
Here what I mean....
Let's say I have a right justification method (much like Aaron's, actually ;-)
) and for a certain type of data, the
data is expected to be 8 characters. So.....
<code>
public String rightJustify(String s, int length) {
(insert your favorite code here)
}
</code>
and then
<code>
public String rightJustify(String s) {
return rightJustify(s,8);
}
</code>
Any comments on either technique would be welcome... I'd like to some
different points of view to help me decide the
merits of these techniques....
thanks
dan