The following is an example code, a method checkUserGuessthat belongs to a class Board.
checkUserGuess
Board
public String checkUserGuess(String aGuess) { // Some processing return result_of_a_guess; }
I have a class SimpleGuessingGamethat uses this method and is satisfied with the processing that this method does. It does not use the return value.
SimpleGuessingGame
Another class ComplexGuessingGameuses this method, and also uses the value returned by the method for further processing.
ComplexGuessingGame
So, we have two cases: one where the return value is used, and the other where it is ignored. Is this a common occurrence or does it indicate poor design?
- , , , :
# 1, # 1, # 2, , :
public void validatekUserGuess(String aGuess) { // Some processing } public String checkUserGuess(String aGuess) { validatekUserGuess(aGuess); // Some additional processing return result_of_a_guess; }
, , "" , .
.
, , , .
public boolean turnOn(Light l);
1:
turnOn(new Light()); log.debug("Attempted to turn on light");
2:
boolean turnedOn = turnOn(new Light()); if (turnedOn) { log.debug("Light is turned on"); } else { log.debug("Not able to turn light on"); }
( result_of_a_guess, ), , . , , ( , , , ).
result_of_a_guess
, result_of_a_guess -, ββ , checkUserGuess :
public void checkUserGuess(String aGuess, Boolean isComplex) { // Some processing if (isComplex) setResult(result_of_a_guess) }
, . -, /. , !