I more than once saw code of the form:
DiceThrower dt = new DiceThrower();
dt.throw(); //this is a void method
int result = dt.getResult();
instead of
DiceThrower dt = new DiceThrower();
int result = dt.throw();
My question is...why? Isn't it better to have the throw
method returning the result? By not doing so, I could even incurr in sometimes forgetting about calling throw()
before getResult()
, accessing always old values of getResult()
. Having both the operation and the result in the same method would circumvent that.
What is your oppinion on the matter?
Thanks