Introduction to J2EE Patterns

author-image
CIOL Bureau
Updated On
New Update

Avijeet Dash and Satyabrata
Dash

Advertisment



Design Patterns more than anything else has now become the lingua franca for the designers and architects. Every vendor names new Design Patterns for some of their best practices. Weblogic documentation has reference to patterns like- such as Read-Mostly Pattern, Data Caching Design Pattern, Exactly-Once-Per-Cluster Design Pattern. TheServerSide.com has a J2EE Pattern repository at http://www.theserverside.com/patterns/index.jsp. You can also find a book on EJB Design Pattern at TheServerSide.com authored by Floyd Marinescu.

Recently Sun Java Center came up with a J2EE Pattern book containing a set of 15 J2EE (Java 2 Platform, Enterprise Edition) Patterns. Most of us use servlets, JSPs, EJBs in different tiers of a distributed application and unknowingly we use many of the J2EE patterns. J2EE Pattern book only formalizes the use of those patterns. Each Pattern is known by its name. So if you are using J2EE Pattern vocabulary, then you would be discussing like Main Front Controller, which uses a set of Intercepting filters and then the Dispatcher selects the right View, which is served by Service to Worker which uses Business Delegates etc. We will discuss those 15 J2EE Patterns in this tutorial.

We had previously discussed the 23 GOF Patterns in Design Patterns Tutorial. The idea of GOF Patterns was to discuss in general, the best fit for various object structures and object collaborations. J2EE Patterns focuses on various best practices in J2EE applications using various technologies such as EJB, JSP and Servlet etc. These Design Patterns not only help us in disciplining our thoughts in object oriented programming but also provide a rich design vocabulary.

Advertisment

Most of the J2EE developers must be well conversant with various J2EE technologies such as EJB, JMS, JSP, Servlet, RMI & JDBC etc. The most common approach in any Web project is to use Servlet/JSP in the presentation tier, Session Beans in the business tier and Entity Beans in persistence tier. So, many common problems found across projects are :

1. Web site is very slow.

2. JSP contains lot of Java code.

3. Client and Server ( Servlet and Session Beans respectively) are tightly coupled to each other.

4. Client makes too many expensive remote calls to Server to collect user data.

To avoid such problems, developers started using patterns and frameworks. The most commonly used framework in J2EE space is M-V-C (Model-View-Controller) framework. Servlet/JSPs are used as Views, Servlet acts as a Controller and all requests are forwarded to the controller Servlet and then Java Beans/ EJBs are used as Models. Struts is one of such popular frameworks that uses M-V-C model. But still many questions like the ones given below confront J2EE application designers.

Advertisment

  1. Where should the preprocessing or post-processing of your requests happen?

  2. How to centralize the request handling control?

  3. Where to encapsulate presentation related data formatting logic?

  4. Whether to use a JSP or Servlet in the view?

  5. Where to encapsulate view management?

  6. Where to store session data?

  7. Where to do the data validation, in data objects or servlets?

  8. Should you use entity beans or not?

  9. How often should I look up the bean, can I cache the look-up?

  10. Should you use CMP or BMP Entity Bean?

  11. What kind of data should be transferred between different tiers?
  12. and many such problems need to be addressed in J2EE project design time.

    Advertisment

    J2EE Patterns do address the above problems and the best design practices for different tiers. J2EE Patterns try to address two kinds of problems, one is framework related like 'how to encapsulate presentation related data formatting logic?' and the other is about refactoring related issues like best practices in J2EE implementation like controlling duplicate form submissions, partitioning data access code.

    We would present one J2EE Pattern at a time and analyze its Context, Problem, Forces and Solutions. We will also discuss best practices for implementation of each of those patterns.



    J2EE Patterns Catalog

    Presentation Tier Patterns


      Advertisment

    1. Intercepting Filter

    2. Front Controller

    3. View Helper

    4. Composite View

    5. Service to Worker

    6. Dispatcher View

    7. Business Tier Patterns


      1. Business Delegate

      2. Value Object

      3. Session Facade

      4. Composite Entity

      5. Value Object Assembler

      6. Value List Handler

      7. Service Locator
      8. Advertisment


        Integration Tie Patterns


        1. Data Access Object

        2. Service Activator
        3. Reference:


          Core J2EE Patterns, Deepak Alur, John Crupi, Dan Malks


          http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns

          tech-news