开发者

Utility vs. Composition vs. Inheritance for JAX-RS Response

开发者 https://www.devze.com 2023-02-11 17:24 出处:网络
I am thinking about writing a utility class that creates and returns a JAX-RS Response.开发者_运维百科The goal is to simplify and standardize the generation of Response\'s.Here\'s the idea:

I am thinking about writing a utility class that creates and returns a JAX-RS Response. 开发者_运维百科The goal is to simplify and standardize the generation of Response's. Here's the idea:

public Object success (Class targetClass, String methodName, Object responseEntity) {

    URI location = UriBuilder.fromResource(targetClass).path(targetClass, methodName).build(localVar1, localVar2);

    LogInfo(location, methodName); //log4J stuff

    return Response.created(location).entity(responseEntity).build();
}

And there would be additional methods for other response types (e.g. canceled, error, etc).

I was curious about how someone else may solve this design problem, perhaps using inheritance or composition.

How have to solved this in the past? Did you create a single utility class as well, or did you use inheritance or composition to design the solution? Why did you go with that design?


This looks like a low-level utility to me. I say don't over think it - creating some kind of bespoke response inheritance hierarchy and or new family of composed types (for the sake of added 'patterniness') feels unnecessary.

I'd create a simple response utility, extract a private method for the commons parts, and rethink this simple design if (and only if) your requirements become more complex.

0

精彩评论

暂无评论...
验证码 换一张
取 消