[ Team LiB ] Previous Section Next Section

MVC Best Practices

MVC best practices are implemented by tried-and-tested J2EE design patterns. These patterns are the result of successful J2EE application implementations. A synopsis of a few of the most successful of these design patterns is presented here.

Presentation Layer Design Patterns

The View Helper design pattern provides a separation of presentation logic from business logic. This separation is accomplished by using view components that implement presentation, while presentation support logic is encapsulated into custom JSP tags or JavaBeans. The view components are usually implemented as JSPs or servlets.

The Composite View design pattern provides a composite presentation view built from subview components. Changes within subview components are propagated to the top-level composite view. The composite view controls the layout of subviews, yielding a consistent look and feel throughout all views. View components are usually implemented as JSPs.

Controller Layer Design Patterns

The Front Controller design pattern provides a central component that controls all application requests. This allows state changes, including views, to be applied uniformly across the application. Additionally, any required code modifications are made in one centralized component. Front controllers are usually implemented as servlets.

The Business Delegate design pattern provides a decoupling of application business logic from using components. This pattern allows complex functionality, such as lookup and remote exception handling, to be accessed using much simpler interfaces. Business delegates are usually implemented as Session EJBs, which further allows a reduction in remote method invocations. The components make one remote call to a Session EJB, which invokes finer-grained services locally (that is, on the server side).

Closely related to the Business Delegate pattern, the Session Fa[cd]ade design pattern provides coarsely grained interfaces to finely grained server-side resources, usually an Entity EJB. The Entity EJB is essentially wrapped within a Session bean. One remote method call is made to the Session bean, which might invoke several methods on the server-side Entity EJB, thereby reducing remote method calls, while providing for much a simpler client-side interface.

The Intercepting Filter design patterns provides interception and redirection of requests and response where needed. This pattern is applicable in application security and other rule-based access implementations. Implementing interception filters helps manage such complex scenarios by avoiding the necessity of coding access implementations within individual JSPs. One intercepting filter is implemented to handle all access concerns. Interception filters are usually servlets that implement the Filter servlet interface.

Model Layer Design Patterns

The Value Object (transfer object) design pattern allows for efficient remote invocations by replacing many finely grained remote method calls with one coarsely grained remote method call. Attributes usually retrieved by the finely grained method invocations are abstracted into one object. One remote method invocation creates and populates the value object locally (server side), and the object is then passed remotely to the client. All attributes are passed in one remote method call (attributes are abstracted within the value [or transfer[ object) versus many remote method calls to populate individual attributes. Value Objects may be implemented as JavaBeans.

The Data Access Object design pattern provides encapsulated data store–specific logic, which yields generic client database interfaces across different data stores. The client uses the same interface to access different databases. The determinant logic (meaning the specific database parameters to execute) is handled by the server side.

For further details about these and other J2EE-recommended design patterns, refer to http://java.sun.com/blueprints/patterns/catalog.html.


The Global Auctions application implements the MVC architecture. The Front Controller–dispatched design pattern is fully implemented within the Controller layer. Servlets are used to control workflow originating from client requests, through application processing, to final delivery of client response. Servlets, as controllers, are implemented to find items, display items, register customers, service logins, and list auction items. These servlets use as business services, Java objects, and session EJBs, in addition to core WebLogic Server–side resources. For the view, servlets and JSP pages using custom JSP tag libraries and JavaBeans implement user presentation. In addition to the previous servlet use case implementations, JSP pages are also implemented for a bid history display and auction report generation. JavaBeans and JSP tag libraries are used to encapsulate data used for item displays and to provide customer information used by a login servlet. Entity EJBs, embellished with value objects, implement an optimized data model; that is, they provide mappings to a relational database complemented by reduced remote method invocations. As an example of GAMS' implementation of the MVC architecture, the finding items use case is shown in Figure 16.4.

Figure 16.4. Finding items use case.


    [ Team LiB ] Previous Section Next Section