SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Unit 7: Design Patterns and Frameworks
 Web presentation layer patterns
         The Model-View-Controller (MVC) architectural pattern
         Catalog of MVC-based patterns
         Other patterns


 Web presentation-business integration patterns


 Business layer architectural patterns


 MVC Web frameworks




dsbw 2008/2009 2q                                                 1
The MVC Architectural Pattern
    Divides an interactive application into three components/levels:
     Model, View and Controller
    Model:
         Contains the functional core of the application
         Encapsulates the appropriate data, and exports procedures that
          perform application-specific processing
    View:
         Displays information to the user
         Obtains the data from the model
         Different views present the information of the model in different ways
    Controller:
         Accepts user input as events
         Translates events to service requests for the model or display requests
          for the view

dsbw 2008/2009 2q                                                                  2
The “Classical” MVC Pattern

                                                    Observer
                                                *
                                                    update()
          1

         Model

data

attach( ob : Observer )
                                    View
                                                                             Controller
detach( ob : Observer )
notify()                                             1         1
                          initialize( m : Model )
getData()                                                          initialize( m : Model, v : View )
                          makeController()
service()                                                          handleEvent()
                          activate()
                                                                   update()
                          display()
                          update()




dsbw 2008/2009 2q                                                                                3
Catalog of MVC-Based Web Presentation Patterns
 Controller Patterns:
        Page Controller
      
       Front Controller
       Application Controller
       Intercepting Filter

 View Patterns
        View Helper
      
       Composite View
       Transform View

 Composite Patterns:
        Dispatcher View
      
       Service to Worker



dsbw 2008/2009 2q                                4
Page Controller




 Each Page Controller component act as the controller for a dynamic
    page on the Web site.
 The basic responsibilities of a Page Controller are:
       Decode the URL and extract any form data
       Invoke model components to process the request data
       Determine which view should display the result page and forward the
        model information to it

dsbw 2008/2009 2q                                                             5
Page Controller: How It Works




dsbw 2008/2009 2q               6
Page Controller: When to Use It
   Page Controller works particularly well in a site where most of the controller
    logic is pretty simple:




                                                          : System
                           : User

                                    service(parameters)

                                          result




   Variant: Page Controller and View implemented by the same Server Page:
    (Model 1)




dsbw 2008/2009 2q                                                               7
Front Controller (Model 2)
 Problem: The system requires a centralized access point for
    request handling. Without a central access point, control code that
    is common across multiple requests is duplicated in numerous
    places. When control code is intermingled with view-creation code,
    the application is less modular and cohesive.
 Forces:
         You want to avoid duplicate control logic.
         You want to apply common logic to multiple requests.
         You want to separate system processing logic from the view.
         You want to centralize controlled access points into your system
 Solution: Use a Front Controller as the initial point of contact for
    handling all related requests. The Front Controller centralizes
    control logic that might otherwise be duplicated, and manages the
    key request handling activities .


dsbw 2008/2009 2q                                                            8
Front Controller: Class Diagram




                    1




dsbw 2008/2009 2q                 9
Front Controller: Sequence Diagram




dsbw 2008/2009 2q                    10
Front Controller + Application Controller




 An Application Controller has two main responsibilities: deciding which
  domain logic to run and deciding the view with which display the response.
 It is useful for designing complex use cases with definite rules about the
  order in which pages should be visited and different views depending on
  the state of objects.
 Separating the Application Controller from the Front Controller allows
  improving the modularity of the system, while enhancing its reusability.
 The Application Controller component is not a Server Page


dsbw 2008/2009 2q                                                         11
Front Controller + Application Controller (cont.)




dsbw 2008/2009 2q                                   12
Application Controller with Mapper




 Application Controller: Uses Mapper to resolve an incoming request
    to the appropriate action and view, to which it delegates or dispatches.
 Mapper: Uses a Map to translate an incoming request into the
    appropriate action and view. A Mapper acts as a factory
 Map: Acts as a dictionary or registry of references to target resources.
 Target: A resource that helps fulfill a particular request (view,
    command)
dsbw 2008/2009 2q                                                         13
Application Controller with Mapper (cont.)




dsbw 2008/2009 2q                            14
Application Controller with Mapper (cont.)




dsbw 2008/2009 2q                            15
Intercepting Filter
   Problem: You want to intercept and manipulate a request and a response
    before and after the request is processed in order to determine if:
         The client has a valid session
         The request path violates any constraint
         You support the browser type of the client
         The client has used a special encoding to send the data
         The request stream is encrypted or compressed
   Forces
       You want centralized, common processing across requests
       You want pre and postprocessing components loosely coupled with core
        request-handling services.
       You want pre and postprocessing components independent of each other and
        self contained to facilitate reuse.

   Solution: Use an Intercepting Filter as a pluggable filter to pre and
    postprocess requests and responses. A Filter Manager combines loosely
    coupled filters in a chain, delegating control to the appropriate filter.


dsbw 2008/2009 2q                                                                  16
Intercepting Filter: Structure, Participants and Responsibilities




   FilterManager: Manages filter processing. It creates the FilterChain with
    the appropriate filters, in the correct order, and initiates processing.
   FilterChain: Ordered collection of independent filters
   Filter: Component that performs a specific pre and/or postprocessing task.
   Target: The resource requested by the client.



dsbw 2008/2009 2q                                                               17
Intercepting Filter: Sequence Diagram




dsbw 2008/2009 2q                       18
Java Filters: Example
 Motivation: HTML forms that include a file upload use a different
    encoding type than that of basic forms. As a result, form data that
    accompanies the upload is not available via simple getParameter()
    invocations. The following filter preprocesses requests to translate
    the encoding type into a single consistent format that makes all form
    data available as request attributes:

      public class MultipartEncodeFilter extends javax.servlet.Filter {
        public void doFilter(javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response,
                             javax.servlet.FilterChain filterChain)
                   throws java.io.IOException, javax.servlet.ServletException {
          String contentType = request.getContentType();
          if (contentType.startsWith(quot;multipart/form-dataquot;) ) {
                For each pair (attributeName, value) obtained from the request
                do request.setAttribute(attributeName, value)
            }
            filterChain.doFilter(request, response); }
      }

dsbw 2008/2009 2q                                                                 19
View Helper
   Problem: You want to separate a view from its processing logic.
       JSP and other template-based views allow embedding scriptlet code
       Embedded scriptlet code cannot be reused easily
       Embedded scriptlet code often acts as control code or performs view preparation
        activities, such as content retrieval.
       Mingling control logic, data access logic and formatting logic leads to problems
        with modularity, reuse, maintenance, and role separation.
   Forces:
       You want to use template-based views, such as JSP.
       You want to avoid embedding program logic in the view.
       You want to separate programming logic from the view to facilitate division of
        labor between software developers and web page designers
   Solution: Use Views to encapsulate formatting code and Helpers to
    encapsulate view-processing logic.
       A View delegates its processing responsibilities to its helper classes,
        implemented as POJOs, custom tags, or tag files.
       Helpers serve as adapters between the view and the model, and perform
        processing related to formatting logic, such as generating an HTML table.

dsbw 2008/2009 2q                                                                        20
View Helper: Structure




 Helper: Encapsulates processing logic for generating and
    formatting a View. A helper typically adapts a PresentationModel for
    a view or provides access to the raw data of the PresentationModel
 PresentationModel: Holds the data retrieved from the business
    service, used to generate the View. It can be either a Business
    Delegate or a DTO

dsbw 2008/2009 2q                                                     21
View Helper: Sequence Diagram




dsbw 2008/2009 2q               22
View Helper: Example with JavaBean and JSTL
<%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=quot;cquot; %>
<jsp:useBean id=quot;welcomeHelperquot; scope=quot;requestquot;
class=quot;WelcomeHelperquot; />
<HTML>
<BODY bgcolor=quot;FFFFFFquot;>
<c:if test = quot;${welcomeHelper.nameExists == true}quot;>
<center><H3> Welcome
<b><c:out value='${welcomeHelper.name}'/> </b><br><br></H3>
</center>
</c:if>
<H4><center>We are happy for your visit!</center></H4>
</BODY></HTML>



dsbw 2008/2009 2q                                                23
Composite View
 Problem: You want to build a view from modular, atomic
    component parts that are combined to create a composite whole,
    while managing the content and the layout independently.
 Forces
       You want common subviews, such as headers, footers and tables
        reused in multiple views, which may appear in different locations within
        each page layout.
       You have content in subviews that frequently changes or might be
        subject to certain access controls, such as limiting access to users in
        certain roles.
       You want to avoid directly embedding and duplicating subviews in
        multiple views which makes layout changes difficult to manage and
        maintain.
 Solution: Use Composite Views that are composed of multiple
    atomic subviews. Each subview of the overall template can be
    included dynamically in the whole, and the layout of the page can
    be managed independently of the content.

dsbw 2008/2009 2q                                                             24
Composite View: Structure




 Template: Represents the page layout
 ViewManager: Uses a Template to enforce a layout into which it places the
  appropriate content.
       A simple ViewManager might use the standard JSP include tag (<jsp:include>)
        to include SimpleView segments into a Template.
       A more sophisticated ViewManager might use POJOs or custom tag helpers to
        provide content and layout management in a more comprehensive and robust
        manner.


dsbw 2008/2009 2q                                                                 25
Composite View: Sequence Diagram




dsbw 2008/2009 2q                  26
Transform View
 Problem: You want a view that processes domain data element by
    element and transforms it into HTML.

 Forces: The data returned by the business layer is either in XML or
    in something automatically transformable to it

 Solution: Use a Transform View that transforms directly from
    domain-oriented XML into (X)HTML by using XSLT (eXtensible
    Stylesheet LanguageTransformations). Normally XSLT does this by
    transforming each XML element into an (X)HTML element.




dsbw 2008/2009 2q                                                  27
Dispatcher View
 Problem: You want a view to handle a request and generate a
    response, with little or no business processing performed before
    rendering the view.
 Forces:
        You have static views
      
       You have views generated from an existing presentation model
       You have views which are independent of any business service
        response
       You have limited business processing

 Solution: Use Dispatcher View with views as the initial access point
    for a request. Business processing, if necessary in limited form, is
    managed by the views.




dsbw 2008/2009 2q                                                          28
Dispatcher View: Structure




 BusinessHelper: Helps the View initiate business processing to handle a
  request
 BusinessService: Encapsulates the business logic and business state. A
  remote business service is accessed via a Business Delegate
 PresentationModel: Holds the data retrieved from the business service
  (DTO).

dsbw 2008/2009 2q                                                       29
Dispatcher View: Sequence Diagram




dsbw 2008/2009 2q                   30
Service To Worker
 Problem: You want to perform core request handling and invoke
    business logic before control is passed to the view

 Forces:
        You want specific business logic executed to service a request
      
        in order to retrieve content that will be used to generate a
        dynamic response.
       You have view selections which may depend on responses from
        business service invocations.
       You may have to use a framework or library in the application


 Solution: Use Service to Worker to centralize control and request
    handling to retrieve a presentation model before turning control over
    to the view. The view generates a dynamic response based on the
    presentation model.


dsbw 2008/2009 2q                                                      31
Service To Worker: Structure




dsbw 2008/2009 2q              32
Service to Worker: Sequence Diagram




dsbw 2008/2009 2q                     33
References
 Books
         ALUR, Deepak et al. Core J2EE Patterns: Best Practices and
          Design Strategies, 2on Edition, Prentice Hall PTR, 2003.
         FOWLER, Martin Patterns of Enterprise Application Architecture,
          Addison Wesley, 2002.


 Webs
         www.corej2eepatterns.com
         java.sun.com/blueprints/corej2eepatterns/
         java.sun.com/blueprints/guidelines/designing_enterprise_applications_2
          e/web-tier/web-tier5.html




dsbw 2008/2009 2q                                                            34

Weitere ähnliche Inhalte

Was ist angesagt?

Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
Pankaj Singh
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
Jee design patterns- Marek Strejczek - Rule Financial
Jee design patterns- Marek Strejczek - Rule FinancialJee design patterns- Marek Strejczek - Rule Financial
Jee design patterns- Marek Strejczek - Rule Financial
Rule_Financial
 

Was ist angesagt? (19)

Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 
Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1Session 38 - Core Java (New Features) - Part 1
Session 38 - Core Java (New Features) - Part 1
 
01.egovFrame Training Book I
01.egovFrame Training Book I01.egovFrame Training Book I
01.egovFrame Training Book I
 
TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6TY.BSc.IT Java QB U6
TY.BSc.IT Java QB U6
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
Ee java lab assignment 4
Ee java lab assignment 4Ee java lab assignment 4
Ee java lab assignment 4
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
 
Java Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVCJava Web Programming [6/9] : MVC
Java Web Programming [6/9] : MVC
 
XPages Workshop: Concepts And Exercises
XPages Workshop:   Concepts And ExercisesXPages Workshop:   Concepts And Exercises
XPages Workshop: Concepts And Exercises
 
TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3TY.BSc.IT Java QB U3
TY.BSc.IT Java QB U3
 
Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Jee design patterns- Marek Strejczek - Rule Financial
Jee design patterns- Marek Strejczek - Rule FinancialJee design patterns- Marek Strejczek - Rule Financial
Jee design patterns- Marek Strejczek - Rule Financial
 
Architectural Design Pattern: Android
Architectural Design Pattern: AndroidArchitectural Design Pattern: Android
Architectural Design Pattern: Android
 
JEE Course - JEE Overview
JEE Course - JEE  OverviewJEE Course - JEE  Overview
JEE Course - JEE Overview
 
intellimeet
intellimeetintellimeet
intellimeet
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
Java Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet AdvancedJava Web Programming [3/9] : Servlet Advanced
Java Web Programming [3/9] : Servlet Advanced
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 

Andere mochten auch (17)

Niño
NiñoNiño
Niño
 
Https _mail-attachment.googleusercontent.com_attachment_ui=2&ik=e50f2c08cb&v...
Https  _mail-attachment.googleusercontent.com_attachment_ui=2&ik=e50f2c08cb&v...Https  _mail-attachment.googleusercontent.com_attachment_ui=2&ik=e50f2c08cb&v...
Https _mail-attachment.googleusercontent.com_attachment_ui=2&ik=e50f2c08cb&v...
 
260 he-phuong-trinh-trong-cac-de-thi
260 he-phuong-trinh-trong-cac-de-thi260 he-phuong-trinh-trong-cac-de-thi
260 he-phuong-trinh-trong-cac-de-thi
 
Sorteo entradas cine Semana de los Goya Ocio y Rutas Valladolid
Sorteo entradas cine Semana de los Goya Ocio y Rutas ValladolidSorteo entradas cine Semana de los Goya Ocio y Rutas Valladolid
Sorteo entradas cine Semana de los Goya Ocio y Rutas Valladolid
 
REVISTA MIRANDISTA 2.013.
REVISTA MIRANDISTA 2.013.REVISTA MIRANDISTA 2.013.
REVISTA MIRANDISTA 2.013.
 
Concurso ortografía 2012
Concurso  ortografía 2012Concurso  ortografía 2012
Concurso ortografía 2012
 
presentación 1
presentación 1presentación 1
presentación 1
 
Afiche curso 6 niños
Afiche curso 6 niñosAfiche curso 6 niños
Afiche curso 6 niños
 
Ventajas y desventajas del software libre y software
Ventajas y desventajas del software libre y softwareVentajas y desventajas del software libre y software
Ventajas y desventajas del software libre y software
 
Client Feedback
Client FeedbackClient Feedback
Client Feedback
 
Buyok music videos
Buyok music videosBuyok music videos
Buyok music videos
 
Doc1
Doc1Doc1
Doc1
 
The Growth of Dublin
The Growth of DublinThe Growth of Dublin
The Growth of Dublin
 
JB Monroe Recommendation
JB Monroe RecommendationJB Monroe Recommendation
JB Monroe Recommendation
 
Κύπρος
ΚύπροςΚύπρος
Κύπρος
 
Konkus
KonkusKonkus
Konkus
 
Representation of Youth Essay Analysis
Representation of Youth Essay AnalysisRepresentation of Youth Essay Analysis
Representation of Youth Essay Analysis
 

Ähnlich wie [DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)

[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
Carles Farré
 

Ähnlich wie [DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3) (20)

Unit 07: Design Patterns and Frameworks (1/3)
Unit 07: Design Patterns and Frameworks (1/3)Unit 07: Design Patterns and Frameworks (1/3)
Unit 07: Design Patterns and Frameworks (1/3)
 
Web tier-framework-mvc
Web tier-framework-mvcWeb tier-framework-mvc
Web tier-framework-mvc
 
Mvc architecture
Mvc architectureMvc architecture
Mvc architecture
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (2/3)
 
MVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVCMVC Pattern. Flex implementation of MVC
MVC Pattern. Flex implementation of MVC
 
Spring Framework-II
Spring Framework-IISpring Framework-II
Spring Framework-II
 
MVC Framework
MVC FrameworkMVC Framework
MVC Framework
 
Ria Mvc
Ria MvcRia Mvc
Ria Mvc
 
Single page application 03
Single page application   03Single page application   03
Single page application 03
 
#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery
 
Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Model View Controller
Model View ControllerModel View Controller
Model View Controller
 
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOSSoftware architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
Software architectural design patterns(MVC, MVP, MVVM, VIPER) for iOS
 
Technoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development servicesTechnoligent providing custom ASP.NET MVC development services
Technoligent providing custom ASP.NET MVC development services
 
MVC
MVCMVC
MVC
 
J2 ee archi
J2 ee archiJ2 ee archi
J2 ee archi
 
Easy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applicationsEasy integration of Bluemix services with your applications
Easy integration of Bluemix services with your applications
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
 
Intro ASP MVC
Intro ASP MVCIntro ASP MVC
Intro ASP MVC
 

Mehr von Carles Farré

DSBW Final Exam (Spring Sementer 2010)
DSBW Final Exam (Spring Sementer 2010)DSBW Final Exam (Spring Sementer 2010)
DSBW Final Exam (Spring Sementer 2010)
Carles Farré
 
Web Usability (Slideshare Version)
Web Usability (Slideshare Version)Web Usability (Slideshare Version)
Web Usability (Slideshare Version)
Carles Farré
 
[DSBW Spring 2009] Unit 09: Web Testing
[DSBW Spring 2009] Unit 09: Web Testing[DSBW Spring 2009] Unit 09: Web Testing
[DSBW Spring 2009] Unit 09: Web Testing
Carles Farré
 
[DSBW Spring 2009] Unit 08: WebApp Security
[DSBW Spring 2009] Unit 08: WebApp Security[DSBW Spring 2009] Unit 08: WebApp Security
[DSBW Spring 2009] Unit 08: WebApp Security
Carles Farré
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
Carles Farré
 
[DSBW Spring 2009] Unit 05: Web Architectures
[DSBW Spring 2009] Unit 05: Web Architectures[DSBW Spring 2009] Unit 05: Web Architectures
[DSBW Spring 2009] Unit 05: Web Architectures
Carles Farré
 
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
Carles Farré
 
[DSBW Spring 2009] Unit 03: WebEng Process Models
[DSBW Spring 2009] Unit 03: WebEng Process Models[DSBW Spring 2009] Unit 03: WebEng Process Models
[DSBW Spring 2009] Unit 03: WebEng Process Models
Carles Farré
 
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
Carles Farré
 
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
Carles Farré
 
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
Carles Farré
 
[ABDO] Data Integration
[ABDO] Data Integration[ABDO] Data Integration
[ABDO] Data Integration
Carles Farré
 
[ABDO] Logic As A Database Language
[ABDO] Logic As A Database Language[ABDO] Logic As A Database Language
[ABDO] Logic As A Database Language
Carles Farré
 

Mehr von Carles Farré (16)

Aplicacions i serveis web (ASW)
Aplicacions i serveis web (ASW)Aplicacions i serveis web (ASW)
Aplicacions i serveis web (ASW)
 
DSBW Final Exam (Spring Sementer 2010)
DSBW Final Exam (Spring Sementer 2010)DSBW Final Exam (Spring Sementer 2010)
DSBW Final Exam (Spring Sementer 2010)
 
Web Usability (Slideshare Version)
Web Usability (Slideshare Version)Web Usability (Slideshare Version)
Web Usability (Slideshare Version)
 
[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond[DSBW Spring 2010] Unit 10: XML and Web And beyond
[DSBW Spring 2010] Unit 10: XML and Web And beyond
 
[DSBW Spring 2009] Unit 09: Web Testing
[DSBW Spring 2009] Unit 09: Web Testing[DSBW Spring 2009] Unit 09: Web Testing
[DSBW Spring 2009] Unit 09: Web Testing
 
[DSBW Spring 2009] Unit 08: WebApp Security
[DSBW Spring 2009] Unit 08: WebApp Security[DSBW Spring 2009] Unit 08: WebApp Security
[DSBW Spring 2009] Unit 08: WebApp Security
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
[DSBW Spring 2009] Unit 06: Conallen's Web Application Extension for UML (WAE2)
 
[DSBW Spring 2009] Unit 05: Web Architectures
[DSBW Spring 2009] Unit 05: Web Architectures[DSBW Spring 2009] Unit 05: Web Architectures
[DSBW Spring 2009] Unit 05: Web Architectures
 
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
[DSBW Spring 2009] Unit 04: From Requirements to the UX Model
 
[DSBW Spring 2009] Unit 03: WebEng Process Models
[DSBW Spring 2009] Unit 03: WebEng Process Models[DSBW Spring 2009] Unit 03: WebEng Process Models
[DSBW Spring 2009] Unit 03: WebEng Process Models
 
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
[DSBW Spring 2009] Unit 02: Web Technologies (2/2)
 
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
[DSBW Spring 2009] Unit 02: Web Technologies (1/2)
 
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering[DSBW Spring 2009] Unit 01: Introducing Web Engineering
[DSBW Spring 2009] Unit 01: Introducing Web Engineering
 
[ABDO] Data Integration
[ABDO] Data Integration[ABDO] Data Integration
[ABDO] Data Integration
 
[ABDO] Logic As A Database Language
[ABDO] Logic As A Database Language[ABDO] Logic As A Database Language
[ABDO] Logic As A Database Language
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)

  • 1. Unit 7: Design Patterns and Frameworks  Web presentation layer patterns  The Model-View-Controller (MVC) architectural pattern  Catalog of MVC-based patterns  Other patterns  Web presentation-business integration patterns  Business layer architectural patterns  MVC Web frameworks dsbw 2008/2009 2q 1
  • 2. The MVC Architectural Pattern  Divides an interactive application into three components/levels: Model, View and Controller  Model:  Contains the functional core of the application  Encapsulates the appropriate data, and exports procedures that perform application-specific processing  View:  Displays information to the user  Obtains the data from the model  Different views present the information of the model in different ways  Controller:  Accepts user input as events  Translates events to service requests for the model or display requests for the view dsbw 2008/2009 2q 2
  • 3. The “Classical” MVC Pattern Observer * update() 1 Model data attach( ob : Observer ) View Controller detach( ob : Observer ) notify() 1 1 initialize( m : Model ) getData() initialize( m : Model, v : View ) makeController() service() handleEvent() activate() update() display() update() dsbw 2008/2009 2q 3
  • 4. Catalog of MVC-Based Web Presentation Patterns  Controller Patterns: Page Controller   Front Controller  Application Controller  Intercepting Filter  View Patterns View Helper   Composite View  Transform View  Composite Patterns: Dispatcher View   Service to Worker dsbw 2008/2009 2q 4
  • 5. Page Controller  Each Page Controller component act as the controller for a dynamic page on the Web site.  The basic responsibilities of a Page Controller are:  Decode the URL and extract any form data  Invoke model components to process the request data  Determine which view should display the result page and forward the model information to it dsbw 2008/2009 2q 5
  • 6. Page Controller: How It Works dsbw 2008/2009 2q 6
  • 7. Page Controller: When to Use It  Page Controller works particularly well in a site where most of the controller logic is pretty simple: : System : User service(parameters) result  Variant: Page Controller and View implemented by the same Server Page: (Model 1) dsbw 2008/2009 2q 7
  • 8. Front Controller (Model 2)  Problem: The system requires a centralized access point for request handling. Without a central access point, control code that is common across multiple requests is duplicated in numerous places. When control code is intermingled with view-creation code, the application is less modular and cohesive.  Forces:  You want to avoid duplicate control logic.  You want to apply common logic to multiple requests.  You want to separate system processing logic from the view.  You want to centralize controlled access points into your system  Solution: Use a Front Controller as the initial point of contact for handling all related requests. The Front Controller centralizes control logic that might otherwise be duplicated, and manages the key request handling activities . dsbw 2008/2009 2q 8
  • 9. Front Controller: Class Diagram 1 dsbw 2008/2009 2q 9
  • 10. Front Controller: Sequence Diagram dsbw 2008/2009 2q 10
  • 11. Front Controller + Application Controller  An Application Controller has two main responsibilities: deciding which domain logic to run and deciding the view with which display the response.  It is useful for designing complex use cases with definite rules about the order in which pages should be visited and different views depending on the state of objects.  Separating the Application Controller from the Front Controller allows improving the modularity of the system, while enhancing its reusability.  The Application Controller component is not a Server Page dsbw 2008/2009 2q 11
  • 12. Front Controller + Application Controller (cont.) dsbw 2008/2009 2q 12
  • 13. Application Controller with Mapper  Application Controller: Uses Mapper to resolve an incoming request to the appropriate action and view, to which it delegates or dispatches.  Mapper: Uses a Map to translate an incoming request into the appropriate action and view. A Mapper acts as a factory  Map: Acts as a dictionary or registry of references to target resources.  Target: A resource that helps fulfill a particular request (view, command) dsbw 2008/2009 2q 13
  • 14. Application Controller with Mapper (cont.) dsbw 2008/2009 2q 14
  • 15. Application Controller with Mapper (cont.) dsbw 2008/2009 2q 15
  • 16. Intercepting Filter  Problem: You want to intercept and manipulate a request and a response before and after the request is processed in order to determine if:  The client has a valid session  The request path violates any constraint  You support the browser type of the client  The client has used a special encoding to send the data  The request stream is encrypted or compressed  Forces  You want centralized, common processing across requests  You want pre and postprocessing components loosely coupled with core request-handling services.  You want pre and postprocessing components independent of each other and self contained to facilitate reuse.  Solution: Use an Intercepting Filter as a pluggable filter to pre and postprocess requests and responses. A Filter Manager combines loosely coupled filters in a chain, delegating control to the appropriate filter. dsbw 2008/2009 2q 16
  • 17. Intercepting Filter: Structure, Participants and Responsibilities  FilterManager: Manages filter processing. It creates the FilterChain with the appropriate filters, in the correct order, and initiates processing.  FilterChain: Ordered collection of independent filters  Filter: Component that performs a specific pre and/or postprocessing task.  Target: The resource requested by the client. dsbw 2008/2009 2q 17
  • 18. Intercepting Filter: Sequence Diagram dsbw 2008/2009 2q 18
  • 19. Java Filters: Example  Motivation: HTML forms that include a file upload use a different encoding type than that of basic forms. As a result, form data that accompanies the upload is not available via simple getParameter() invocations. The following filter preprocesses requests to translate the encoding type into a single consistent format that makes all form data available as request attributes: public class MultipartEncodeFilter extends javax.servlet.Filter { public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain filterChain) throws java.io.IOException, javax.servlet.ServletException { String contentType = request.getContentType(); if (contentType.startsWith(quot;multipart/form-dataquot;) ) { For each pair (attributeName, value) obtained from the request do request.setAttribute(attributeName, value) } filterChain.doFilter(request, response); } } dsbw 2008/2009 2q 19
  • 20. View Helper  Problem: You want to separate a view from its processing logic.  JSP and other template-based views allow embedding scriptlet code  Embedded scriptlet code cannot be reused easily  Embedded scriptlet code often acts as control code or performs view preparation activities, such as content retrieval.  Mingling control logic, data access logic and formatting logic leads to problems with modularity, reuse, maintenance, and role separation.  Forces:  You want to use template-based views, such as JSP.  You want to avoid embedding program logic in the view.  You want to separate programming logic from the view to facilitate division of labor between software developers and web page designers  Solution: Use Views to encapsulate formatting code and Helpers to encapsulate view-processing logic.  A View delegates its processing responsibilities to its helper classes, implemented as POJOs, custom tags, or tag files.  Helpers serve as adapters between the view and the model, and perform processing related to formatting logic, such as generating an HTML table. dsbw 2008/2009 2q 20
  • 21. View Helper: Structure  Helper: Encapsulates processing logic for generating and formatting a View. A helper typically adapts a PresentationModel for a view or provides access to the raw data of the PresentationModel  PresentationModel: Holds the data retrieved from the business service, used to generate the View. It can be either a Business Delegate or a DTO dsbw 2008/2009 2q 21
  • 22. View Helper: Sequence Diagram dsbw 2008/2009 2q 22
  • 23. View Helper: Example with JavaBean and JSTL <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=quot;cquot; %> <jsp:useBean id=quot;welcomeHelperquot; scope=quot;requestquot; class=quot;WelcomeHelperquot; /> <HTML> <BODY bgcolor=quot;FFFFFFquot;> <c:if test = quot;${welcomeHelper.nameExists == true}quot;> <center><H3> Welcome <b><c:out value='${welcomeHelper.name}'/> </b><br><br></H3> </center> </c:if> <H4><center>We are happy for your visit!</center></H4> </BODY></HTML> dsbw 2008/2009 2q 23
  • 24. Composite View  Problem: You want to build a view from modular, atomic component parts that are combined to create a composite whole, while managing the content and the layout independently.  Forces  You want common subviews, such as headers, footers and tables reused in multiple views, which may appear in different locations within each page layout.  You have content in subviews that frequently changes or might be subject to certain access controls, such as limiting access to users in certain roles.  You want to avoid directly embedding and duplicating subviews in multiple views which makes layout changes difficult to manage and maintain.  Solution: Use Composite Views that are composed of multiple atomic subviews. Each subview of the overall template can be included dynamically in the whole, and the layout of the page can be managed independently of the content. dsbw 2008/2009 2q 24
  • 25. Composite View: Structure  Template: Represents the page layout  ViewManager: Uses a Template to enforce a layout into which it places the appropriate content.  A simple ViewManager might use the standard JSP include tag (<jsp:include>) to include SimpleView segments into a Template.  A more sophisticated ViewManager might use POJOs or custom tag helpers to provide content and layout management in a more comprehensive and robust manner. dsbw 2008/2009 2q 25
  • 26. Composite View: Sequence Diagram dsbw 2008/2009 2q 26
  • 27. Transform View  Problem: You want a view that processes domain data element by element and transforms it into HTML.  Forces: The data returned by the business layer is either in XML or in something automatically transformable to it  Solution: Use a Transform View that transforms directly from domain-oriented XML into (X)HTML by using XSLT (eXtensible Stylesheet LanguageTransformations). Normally XSLT does this by transforming each XML element into an (X)HTML element. dsbw 2008/2009 2q 27
  • 28. Dispatcher View  Problem: You want a view to handle a request and generate a response, with little or no business processing performed before rendering the view.  Forces: You have static views   You have views generated from an existing presentation model  You have views which are independent of any business service response  You have limited business processing  Solution: Use Dispatcher View with views as the initial access point for a request. Business processing, if necessary in limited form, is managed by the views. dsbw 2008/2009 2q 28
  • 29. Dispatcher View: Structure  BusinessHelper: Helps the View initiate business processing to handle a request  BusinessService: Encapsulates the business logic and business state. A remote business service is accessed via a Business Delegate  PresentationModel: Holds the data retrieved from the business service (DTO). dsbw 2008/2009 2q 29
  • 30. Dispatcher View: Sequence Diagram dsbw 2008/2009 2q 30
  • 31. Service To Worker  Problem: You want to perform core request handling and invoke business logic before control is passed to the view  Forces: You want specific business logic executed to service a request  in order to retrieve content that will be used to generate a dynamic response.  You have view selections which may depend on responses from business service invocations.  You may have to use a framework or library in the application  Solution: Use Service to Worker to centralize control and request handling to retrieve a presentation model before turning control over to the view. The view generates a dynamic response based on the presentation model. dsbw 2008/2009 2q 31
  • 32. Service To Worker: Structure dsbw 2008/2009 2q 32
  • 33. Service to Worker: Sequence Diagram dsbw 2008/2009 2q 33
  • 34. References  Books  ALUR, Deepak et al. Core J2EE Patterns: Best Practices and Design Strategies, 2on Edition, Prentice Hall PTR, 2003.  FOWLER, Martin Patterns of Enterprise Application Architecture, Addison Wesley, 2002.  Webs  www.corej2eepatterns.com  java.sun.com/blueprints/corej2eepatterns/  java.sun.com/blueprints/guidelines/designing_enterprise_applications_2 e/web-tier/web-tier5.html dsbw 2008/2009 2q 34