J2EE Design Patterns

J2EE [java 2 Enterprise Edition] design patterns are the good practices to solve some common recurring coding problems. J2EE Design Patterns is use to develop a good web architecture and application which are flexible and easy to maintain. Applying design patterns implies fast development.

J2EE Design Patterns are divided into 3 Categories

  • Presentation Layer
    • Intercepting filter
    • Front controller
    • Composite view
    • View helper
    • Dispatcher view
    • Service to work
  • Business Layer
    • Business Delegate
    • Service Locator
    • Session Façade
    • Transfer Object
    • Transfer Object Assembler
    • Composite Entity
    • Value List Handler
  • Integration Layer
    • Service Activator
    • Data Access Object

Presentation Layer

Presentation layer consist of only view part that is look and feel of the webpages. This layer uses jsp, servlet, html, css, j.s, jquery etc. technologies which are use for developing webpage designing. There are several design patterns are as under

  • Intercepting filter
  • Front controller
  • Composite view
  • View helper
  • Dispatcher view
  • Service to work

Intercepting filter

Intercepting Filter use as a pluggable filter to pre and post process requests and responses. A filter manager combines loosely coupled filters in a chain, delegating control to the appropriate filter. In this way, you can add, remove, and combine these filters in various ways without changing existing code.
Intercepting filter a pluggable component design to intercept incomming requests and outgoing responses, provide common services in a standard manner (independently) without changing core processing code.

Uses
  • centralized, common processing across requests, such as checking the data-encoding scheme of each request, logging information about each request, or compressing an outgoing response.
  • pre and post processing components loosely coupled with core request-handling services to facilitate unobtrusive addition and removal.
Advantages
  • Centralizes control with loosely coupled handlers.
  • Improves reusability.

Front Controller

Front controller is used when some processing is required before showing the view to user i.e controller runs first. Front controller is mainly a servlet which take the request from client (web browser) and pass it to the model, model do some calculation and send it to controller and then controller send it to view.
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.

Uses
  • When You want to avoid duplicate control logic.
  • When you want to apply common logic to multiple requests.
  • When you want to separate system processing logic from the view.
  • want to centralize controlled access points into your system.
Advantages
  • Improves manageability
  • Improves reusability.

Composite View

Composite view design pattern is used when multiple subviews are directly embedded to make a single view or layout or template. A composite view is a view that is an aggregate of multiple subviews.
Composite view is a combination of  subviews, such as headers, footers and tables reused in multiple views, which may appear in different locations within each page layout.

Uses
  •  Use this pattern when the content in subviews is that which changes frequently.
  • Avoid directly embedding and duplicating subviews in multiple views which makes layout changes difficult to manage and maintain.
Advantages
  • Improves modularity and reuse.
  • Adds role-based or policy-based control.
  • Enhances maintainability.

View Helper

As a good programmer your core responsibility is to segregate all the code in different layers and follow DRY and SRP principals i.e view should be used only for designing and formatting porpose in jsp files and other data processing/calculation code should be kept in other classes or layer which will help in maintenance and it also increase code reusability .
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.

Uses
  •   Avoid embedding program logic in the view.
  • separate programming logic from the view to facilitate division of labor between software developers and web page designers.
Advantages
  • Improves application partitioning, reuse, and maintainability.
  • Improves role separation.
  • Eases testing.

Dispatcher View

Dispatcher view is a combination of a controller and dispatcher with views and view helpers to handle client requests and prepare a dynamic presentation content as the response. A dispatcher view is responsible for view management and navigation and can be encapsulated either within a controller, a view, or a separate component working in with their coordination.

Uses
  • Used for static views.
  • Use when views generated from an existing presentation model.
  • Use where limited business processing.
Advantages
  • Improves reusability and maintainability.
  • Help in application partitioning.
  • Helps in role seperation.

Service To Work

The Service to Worker pattern is like the Dispatcher View pattern which describes a common combination of other patterns. It Combine a controller and dispatcher with views and view helpers to handle client requests and prepare a dynamic content as the response. A controller delegates content fetching to view helpers, which manage the intermediate model for the view. A dispatcher is responsible for view management and navigation and can be encapsulated either within a controller or a separate component.

Uses
  • Use when you want a specific business logic executed when a request come from client in order to retrieve content that will generate a dynamic response.
  • Use when view selections is required on responses from business service invocations.
Advantages
  • Centralizes control
  • Improves modularity, reusability, and maintainability
  • Improves role separation.