chibenwa commented on code in PR #2404:
URL: https://github.com/apache/james-project/pull/2404#discussion_r1751904705
##########
server/protocols/webadmin/webadmin-core/src/main/java/org/apache/james/webadmin/routes/HealthCheckRoutes.java:
##########
@@ -145,11 +153,16 @@ private Collection<HealthCheck>
getHealthChecks(Set<ComponentName> selectedCompo
.toList();
}
- private int getCorrespondingStatusCode(ResultStatus resultStatus) {
+ private int getCorrespondingStatusCode(ResultStatus resultStatus, boolean
isStrict) {
Review Comment:
Please can we increase a bit the level of design of the produced code?
Rather than producing if-else programing based on raw types and where we
overload the method parameters with boolean paramters, can we leverage the
strengths of object oriented programming?
Ref: Robert C. Martin's Clean Code Tip #12: Eliminate Boolean Arguments
CF https://dev.to/rweisleder/the-flag-parameter-anti-pattern-1j82
Example of how this could be done to get a better code
```
enum StatusCodeConverter {
STRICT(result -> {
// Java 21 pattern matching would make this GREAT!
switch(result) {
case HEALTHY:
return HttpStatus.OK_200;
case DEGRADED:
case UNHEALTHY:
return HttpStatus.SERVICE_UNAVAILABLE_503;
}),
RELAXED(result -> ...);
public static StatusCodeConverter parse(Request req) {...}
private final Function<ResultStatus, Integer> operation;
public int getCorrespondingStatusCode(ResultStatus resultStatus) {
return operation.apply(resultStatus);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]