Separating Accessors and Mutators
If we call a method to access an object, we don't expect the object to mutate
Rule of thumb:
Mutators should return
void
Example of violation:
StringTokenizer t = . . .; String s = t.nextToken();
Yields current token
and
advances iteration
What if I want to read the current token again?
previous
|
start
|
next
.... [Slide 23] ....