Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet Computing KUT Youn-Hee Han

Similar presentations


Presentation on theme: "Internet Computing KUT Youn-Hee Han"— Presentation transcript:

1 Internet Computing Laboratory @ KUT Youn-Hee Han
Wrapper Pattern Internet Computing KUT Youn-Hee Han

2 Wrapper Pattern Wrapper Pattern  Adapter Pattern 정의
특정 클래스의 인터페이스를 그 클래스의 이용자가 원하는 다른 인터페이스로 전환시킨다. 인터페이스가 호환되지 않아 상호 작용할 수 없는 경우에, Adapter를 이용하여 클래스 사이의 인터페이스의 호환성을 보장할 수 있다. 실생활에서 전기 플러그의 형태가 맞지 않은 경우에 어댑터(adapter)를 사용하는 것과 같은 이치라고 할 수 있다. 실제 구현 시에 인터페이스를 맞추기 위하여 결과적으로 새로운 인터페이스로 클래스를 감싸게 되기 때문에 Wrapper 패턴이라고도 한다. Web Programming

3 ServletRequest vs. Its Wrapper
public interface ServletRequest Defines an object to provide client request information to a servlet. A ServletRequest object provides data including parameter name and values, attributes, and an input stream. Interfaces that extend ServletRequest can provide additional protocol-specific data (for example, HTTP data is provided by HttpServletRequest.) public class ServletRequestWrapper implements ServletRequest Provides a convenient implementation of the ServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object. Web Programming

4 HttpServletRequest vs. Its Wrapper
public interface HttpServletRequest extends ServletRequest Extends the ServletRequest interface to provide request information for HTTP servlets. The servlet container (tomcat) creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc). public class HttpServletRequestWrapper extends ServletRequestWrapper implements HttpServletRequest Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object. 참고: Web Programming

5 각 클래스들의 관계 클래스간의 관계 실제 코드로의 매핑 extends ServletRequest
HttpServletRequest implements implements ServletRequestWrapper extends HttpServletRequestWrapper - 실제 이곳으로 바인딩 되는 객체는 Tomcat에서 자체적으로 제공하는 클래스의 객체임. - 사용자가 쉽게 그 클래스를 찾기는 힘듦 public class HelloServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { …. } - 즉, Tomcat을 사용하는 프로그래머가 일부로 HttpServletRequestWrapper 를 사용하지 않으면 HttpServletRequestWrapper 는 실제 사용되지 않는다. Web Programming

6 각 클래스들의 관계 FileUploadRequestWrapper 의 실체 및 역할 extends ServletRequest
HttpServletRequest implements implements ServletRequestWrapper extends HttpServletRequestWrapper extends FileUploadRequestWrapper processFileUpload2.jsp (p.455, 456) FileUploadRequestWrapper Tomcat에서 자체적으로 제공하는 HttpServletRequest를 Implement 하는 클래스 Web Programming


Download ppt "Internet Computing KUT Youn-Hee Han"

Similar presentations


Ads by Google