Re: Method naming convention required
dagon@dagon.net (Mark Rafn) writes:
The OP was asking about (and I agree with) how to determine
which methods on a mutable object actually change the state.
This might be considered to be an implementation detail,
which should not be visible to a client.
Why should a client programmer need to know this?
For example,
shape.rotate( a )
might rotate a shape around its center (of gravity) by the
angle a.
After
Shape shape = new Rectangle();
"rotate" will change the state, while after
Shape shape = new Circle();
"rotate" might be a no-operation (not changing the state of
its object). So "rotate" in the interface "Shape" can not be
named to reflect both a state change and no state change.
Moreover, for certain values of a, like "0" or multiples of
360 degrees, "rotate( a )" may not change the state of a
rectangle.
Or, when a method does not change the state of its object, but
the state of a referenced object, should this considered to be
a change of the state of the object, too?
Does
System.out.println( "a" );
change the state of the object "System.out"? If this is
take to represent the console, the answer is "yes", because
text is added to the console. However, the answer might
be "no", if only the modification of primitve fields are
considered to be a change.