The specific example I have in mind is javax.servlet.ServletResponseWrapper:
public class ServletResponseWrapper implements ServletResponse {
private ServletResponse response;
/**
* The default behavior of this method is to call setCharacterEncoding(String charset)
* on the wrapped response object.
*
* @since 2.4
*/
public void setCharacterEncoding(String charset) {
this.response.setCharacterEncoding(charset);
}
/**
* The default behavior of this method is to return getCharacterEncoding()
* on the wrapped response object.
*/
public String getCharacterEncoding() {
return this.response.getCharacterEncoding();
}
/**
* The default behavior of this method is to return getOutputStream()
* on the wrapped response object.
*/
public ServletOutputStream getOutputStream() throws IOException {
return this.response.getOutputStream();
}
/** and so on **/
}
ServletResponseWrapper
does nothing. It only passes execution to the nested object. So ServletResponseWrapper
cannot function unless there is some other class (let's say ServletResponseConcrete
) which also implements ServletResponse
and does the real work.
In what context would you be able to use ServletResponseWrapper
that you couldn't just use ServletResponseConcrete
directly? This make absolutely no sense to me. I don't see how it's useful for subclassing either. If I subclass ServletResponseWrapper, then I have to implement every function anyways, so why not just create a class that implements ServletResponse
directly?