Avijeet Dash and Satyabrata
Dash
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.
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.
and many such problems need to be addressed in J2EE project design time.
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
Business Tier Patterns
Integration Tie Patterns
Reference:
Core J2EE Patterns, Deepak Alur, John Crupi, Dan Malks
http://developer.java.sun.com/developer/technicalArticles/J2EE/patterns