이 클래스는 추상 클래스가 아니어야합니까? 만약 내가 직접 사용한다면 어쨌든 나에게 기본 객체를 줄 것이므로 서브 클래 싱을해야하고 내 관심사를 재정의해야한다.HttpServletRequestWrapper 클래스가 추상이 아닌 이유
public class HttpRequestWrapper extends HttpServletRequestWrapper {
private static final Logger logger = LoggerFactory
.getLogger(HttpRequestWrapper.class);
private final byte[] body;
private static Gson gson = new Gson();
public HttpRequestWrapper(HttpServletRequest request) throws IOException {
super(request);
// Read the request body and save it as a byte array
InputStream is = super.getInputStream();
body = IOUtils.toByteArray(is);
}
@Override
public ServletInputStream getInputStream() throws IOException {
return new ServletInputStreamImpl(new ByteArrayInputStream(body));
}
@Override
public BufferedReader getReader() throws IOException {
String encBody = getCharacterEncoding();
if (encBody != null && encBody != enc) {
enc = encBody;
}
return new BufferedReader(new InputStreamReader(getInputStream(), enc));
}
xxxxxxxx more code xxxxxx
}
내가 직접 따라서 왜 추상적하지 HttpServletRequestWrapper의 객체를 생성하는 이점을 이해하지 못하고 다음과 같이 내가 사용하고있는 방법은? 핵심 통찰력을 놓치고 있습니까? 래퍼 주위 래퍼 (내가 뭘하는지) 중복인가?
업데이트 1 : 동일한 기능을 수행하는 데 사용할 수있는 다른 라이브러리가 있습니까?
실제로이 클래스의 기본 동작은 기본 구현으로 되돌아 가고 추상 동작으로도 동일한 동작을 얻을 수 있습니다. 하나는 추상 클래스를 정의하고 모든 메소드의 구현을 제공 할 수 있습니다. 추상적이라는 이점은 개발자의 마음에 이것이 래퍼 클래스로 직접 사용될 수 있다는 의심을 일으키지 않는다는 것입니다. – Richeek