There are methods in classes like "addSomething()". This can be successful or not successful. The status of the success can therefore be displayed with a boolean return value. But sometimes a method invocation can fail because of several reasons. "false" displays that, but only in a general manner. Sometimes the programmer wants to know the reason, why something failed. Is it, for this purpose, useful to provide an own report class that offers functionality like that?
public class Report {
private final boolean success;
private final String message;
public Report(boolean success) {
this.success = success;
this.message = "empty message";
}
public Report(boolean success, String message) {
this(success);
this.message = message;
}
public boolean wasSuccessful() {
return success;
}
public String getMessage() {
return message;
}
}
Then you can decide if you want to get a general success report with "wasSuccessful()" or if you also want to log the exact reason with "getMessage()".