158 CHAPTER 3: Best Practices in Java EE Web Development
Note In spite of applying the Java EE patterns and incremental evolution, some applications fail due to
wrong architectural decisions. These wrong architectural decisions are documented so that you do not
make the same mistake again. These documented wrong architectural decisions are called Antipatterns.
J2EE Antipatterns by Bill Dudney, Stephen Asbury, Joseph K. Krozak, and Kevin Wittkopf (Wiley, 2003) is an
excellent resource for Antipatterns.
Java Web Frameworks
You learned that MVC and the Java EE web tier patterns together facilitate the architectural foundation
for building reusable, maintainable, and extensible web applications. As developers gather more
experience, they start discovering generic objects that can be used over and over, and patterns begin
to emerge. Once you have a collection of such generic objects, a framework begins to emerge. A
framework is a collection of generic objects and other supporting classes that provide the infrastructure
for application development. Frameworks are, essentially, a collection of design patterns guarded by the
basic framework principles discussed next. A Java framework uses two types of patterns.
OO patterns
Java EE patterns
A framework uses OO patterns for its own construction to address the architectural problem domain,
such as extensibility, maintainability, reusability, performance, and scalability. Both OO patterns
and Java EE patterns address the business problem domain areas, such as processing requests,
authentication, validation, session management, and view management to name a few. .Frameworks
address these two major architectural and business problem areas by providing patterns based
generic objects and supporting classes, closely guarded by the following key principles:
Configurability: Configurability is the ability of the framework to be able to use
the metadata to alter the behavior of the framework.
Inversion of control: In traditional programming style, the problem domain code
controls the flow of the application execution. Inversion of control refers to the
technique where reusable code controls the execution of the problem domain
code, thus controlling the flow of the application execution.
Loose coupling: This principle refers to the independence of the collaborating
classes in the framework with which each collaborating class can be altered
without influencing the other collaborating class.
Separation of concerns: This principle refers to the need to classify the problem
domain areas and deal with them in an isolated manner so that the concerns of
one problem area do not influence the concerns of another problem area. The
multitiered Java EE architecture we saw in Chapter 1 is driven by the principle of
the separation of concerns.
Automating common functionalities: A framework provides mechanisms for
automated solutions to the mundane functionalities of the domain.