Any suggestions for me to refactor the class, all the static methods are the same, only one of the variable code is different.
public class SuccessResponseBuilder {
static ResponseCode code = ResponseCode.OK;
public static <T> @NotNull ResponseBean build() {
return ResponseBean.builder(code, null);
}
public static <T> ResponseBean build(T data) {
return ResponseBean.builder(code, data);
}
}
public class ErrorResponseBuilder {
static ResponseCode code = ResponseCode.ERROR;
public static <T> @NotNull ResponseBean build() {
return ResponseBean.builder(code, null);
}
public static <T> ResponseBean build(T data) {
return ResponseBean.builder(code, data);
}
}
The client will used this way to get the result
ErrorResponseBuilder.build(e.getMessage());
SuccessResponseBuilder.build("ok");