Do not use the return value of the method, is this a bad design?

The following is an example code, a method checkUserGuessthat belongs to a class 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.

Another class ComplexGuessingGameuses this method, and also uses the value returned by the method for further processing.

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?

+4
source share
3 answers

- , , , :

  • - ,
  • ,

# 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;
}

, , "" , .

+2

.

, , , .

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");
}
+1

( 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)
}

, . -, /. , !

-2

All Articles