Beruflich Dokumente
Kultur Dokumente
In this section we have tried to cover how to use and identify design
patterns, in J2EE applications. The interest in design patterns has been
around for a number of years in the software industry. However, interest
among mainstream software developers is a fairly recent development
actually it takes a highly experienced engineer to recognize a pattern, it
requires collaboration, and it requires ongoing refinements.
There are a number of patterns that have been identified by the Sun Java
Center for the presentation tier. We have tried to explain them in this section,
we are starting with a small explanation and then a complete section on each
patterns.
Service Locator: Multiple clients can reuse the Service Locator object to
reduce code complexity, provide a single point of control, and improve
performance by providing a caching facility.
Data Access Object: Abstracts and encapsulate all access to the data
source. The DAO manages the connection with the data source to obtain and
store data.
J2EE DESIGN PATTERNS - Intercepting Filters
Different type of processing is required for the different type of request
received by the presentation tier request handler. Some requests are simply
forwarded to the appropriate handler component, while other requests must
be processed being further processed. We require Preprocessing and post-
processing of a client Web request and response.
Filters: These are the individual filters that are mapped to a target. The
Filter Chain coordinates their processing.
Target: The Target is the resource requested by the client.
Strategies-
Base Filter Strategy: A base filter serves as a common superclass for all
filters. Common features can be encapsulated in the base filter and shared
among all filters. For example, a base filter is a good place to include default
behavior for the container callback methods in the Declared Filter Strategy.
Template Filter Strategy: Using a base filter from which all others inherit
allows the base class to provide template method [Gof] functionality. In this
case, the base filter is used to dictate the general steps that every filter must
complete, while leaving the specifics of how to complete that step to each
filter subclass. Typically, these would be coarsely defined, basic methods that
simply impose a limited structure on each template. This strategy can be
combined with any other filter strategy, as well.
The controller provides a centralized entry point that controls and manages
Web request handling. By centralizing decision points and controls, the
controller also helps reduce the amount of Java code, called scriptlets,
embedded in the JavaServer Pages (JSP) page.
Centralizing control in the controller and reducing business logic in the view
promotes code reuse across requests. It is a preferable approach to the
alternative-embedding code in multiple views-because that approach may
lead to a more error-prone, reuse-by-copy- and-paste environment.
Typically, a controller coordinates with a dispatcher component. Dispatchers
are responsible for view management and navigation. Thus, a dispatcher
chooses the next view for the user and vectors control to the resource.
Dispatchers may be encapsulated within the controller directly or can be
extracted into a separate component.
View
A view represents and displays information to the client. The view retrieves
information from a model. Helpers support views by encapsulating and
adapting the underlying data model for use in the display.
The solution to this is to use composite views that are composed of multiple
atomic sub views. Each component of the template may be included
dynamically into the whole and the layout of the page may be managed
independently of the content.
This solution provides for the creation of a composite view based on the
inclusion and substitution of modular dynamic and static template fragments.
It promotes the reuse of atomic portions of the view by encouraging modular
design. It is appropriate to use a composite view to generate pages
containing display components that may be combined in a variety of ways.
The layout of the page is managed and modified independent of the subview
content.
Another benefit of this pattern is that Web designers can prototype the layout
of a site, plugging static content into each of the template regions. As site
development progresses, the actual content is substituted for these
placeholders.
Included View
An included view is a subview that is one atomic piece of a larger whole view.
This included view could also potentially be a composite, itself including
multiple subviews.
2. All the client side components have to be aware of the location details of
the business services say that each component has to use the JNDI lookup
service to locate the required remote interfaces.
Business delegate handle all the code that access the business services in the
selected vendor software. When the vendor or the vendor software changes
only changes that need to be made is to the company’s allocation software
are changes to Business delegate, to access the business services. The
presentation layer need not to be modified.
The business delegate object abstracts the business services API and
provides standard interface to al the client components. It hides the
underlying implementation detail such as lookup mechanism and the API of
the business services. This reduces the coupling between the clients and the
business services.
Another benefit is that the delegate may cache results and references to
remote business services. Caching can significantly improve performance,
because it limits unnecessary and potentially costly round trips over the
network.
Client components: The client components which are jsp pages and servlets
in the presentation tier, delegate the work of locating the business service
providers and the work of invoking the business service API methods to the
Business Delegate objects.
If the client needs to display or update a set of attributes that live on the
server, these attributes could live in an entity bean or be accessible through a
session bean. The client could get or update the data is by loading many
parameters into a method call, when updating data on the server, or by
making multiple fine-grained calls to the server to retrieve data. Every call
between the client and server is a remote method call with substantial
network overhead. If the client application calls the individual getter and
setter methods that require or update single attribute values, it will require
as many remote calls as there are attributes. The individual calls generate a
lot of network traffic and affects severely the system performance.
The solution to this problem is to use a plain java classes called Value Objects
or Transfer Objects, which encapsulate the bulk business data. A single
method call is used to send and retrieve the Transfer Object / Value Objects.
When the client requests the enterprise bean for the business data, the
enterprise bean can construct the Transfer Object, populate it with its
attribute values, and pass it by value to the client.
When an enterprise bean uses a Transfer Object / Value Objects, the client
makes a single remote method invocation to the enterprise bean to request
the Transfer Object / Value Objects instead of numerous remote method calls
to get individual attribute values. The enterprise bean then constructs a new
Transfer Object instance, copies values into the object and returns it to the
client. The client receives the Transfer Object / Value Objects and can then
invoke accessor or getter methods on the Transfer Object to get the
individual attribute values from the Transfer Object. The implementation of
the Transfer Object / Value Objects may be such that it makes all attributes
public. Because the Transfer Object / Value Objects is passed by value to the
client, all calls to the Transfer Object / Value Objects instance are local calls
instead of remote method invocations.
Client
This represents the client of the enterprise bean. The client can be an end-
user application, like jsp, servlets or a java applet, as in the case of a rich
client application that has been designed to directly access the enterprise
beans. The client can be Business Delegates or a different BusinessObject.
Business Object
The Business Object represents a role in this pattern that can be fulfilled by a
session bean, an entity bean, or a Data Access Object (DAO). The
BusinessObject is responsible for creating the Transfer Object and returning it
to the client upon request. The Business Object may also receive data from
the client in the form of a Transfer Object / Value Objects and use that data
to perform an update.
If the client needs to display or update a set of attributes that live on the
server, these attributes could live in an entity bean or be accessible through a
session bean. The client could get or update the data is by loading many
parameters into a method call, when updating data on the server, or by
making multiple fine-grained calls to the server to retrieve data. Every call
between the client and server is a remote method call with substantial
network overhead. If the client application calls the individual getter and
setter methods that require or update single attribute values, it will require,
as many remote calls as there are attributes. The individual calls generate a
lot of network traffic and affects severely the system performance.
The solution to this problem is to use a plain java classes called Value Objects
or Transfer Objects, which encapsulate the bulk business data. A single
method call is used to send and retrieve the Transfer Object / Value Objects.
When the client requests the enterprise bean for the business data, the
enterprise bean can construct the Transfer Object, populate it with its
attribute values, and pass it by value to the client.
When an enterprise bean uses a Transfer Object / Value Objects, the client
makes a single remote method invocation to the enterprise bean to request
the Transfer Object / Value Objects instead of numerous remote method calls
to get individual attribute values. The enterprise bean then constructs a new
Transfer Object instance, copies values into the object and returns it to the
client. The client receives the Transfer Object / Value Objects and can then
invoke accessor or getter methods on the Transfer Object to get the
individual attribute values from the Transfer Object. The implementation of
the Transfer Object / Value Objects may be such that it makes all attributes
public. Because the Transfer Object / Value Objects is passed by value to the
client, all calls to the Transfer Object / Value Objects instance are local calls
instead of remote method invocations.
Client
This represents the client of the enterprise bean. The client can be an end-
user application, like jsp, servlets or a java applet, as in the case of a rich
client application that has been designed to directly access the enterprise
beans. The client can be Business Delegates or a different BusinessObject.
Business Object
The Business Object represents a role in this pattern that can be fulfilled by a
session bean, an entity bean, or a Data Access Object (DAO). The
BusinessObject is responsible for creating the Transfer Object and returning it
to the client upon request. The Business Object may also receive data from
the client in the form of a Transfer Object / Value Objects and use that data
to perform an update.