dimanche 13 août 2023

Should response handlers in Spring be interfaced?

I am designing a spring boot application and I am writing a response handling class

public class ResponseHandlerImpl extends ResponseHandler {

public ResponseEntity<Object> generateResponse( Object responseObject, String message, HttpStatus status){
        HashMap<String, Object> map = new HashMap<>();
            map.put("data", responseObject);
            map.put("message", message);
            map.put("status", status);
            return new ResponseEntity<Object>(map, status);
        }
}

The thing is, is it best practice to make the responsehandler class static or extend from an interface?

I feel like error response handlers should be static. But I'm not too sure.

Or should it extend from an interface and not be static?

Any guidance is very much appreciated. How would you code your response handler class?

Aucun commentaire:

Enregistrer un commentaire