Java Reference
In-Depth Information
enough to guarantee his safety throughout his paddling career. Should he ever
find the need for a paddle in his hands after his roll, he'd need to learn to apply
his tools appropriately. Likewise, using distributed frameworks and develop-
ment environments does save us from many implementation details, but it
should not absolve us of understanding the tools that we employ.
The Round-tripping antipattern made database-stored procedures popular,
even in the face of significant maintenance and design trade-offs. The perfor-
mance costs for round-tripping were simply too great to ignore. This antipat-
tern also doomed many CORBA and Smalltalk architectures, though we can
refactor them with some of the same techniques that we present in this chap-
ter. Many EJB environments allow us to use distribution and persistence as
easily as we might flip a switch, but we must also understand the implications of
using that switch. One such implication is performance.
Refactoring the BBS with a facade
We can think of our distributed interface as low-tech communication across a
turbulent river. Each request for information must be written down on a piece
of paper and carefully ferried across the dangerous river. We could tediously
paddle every page across the river individually. Eventually, we might decide that
we'd like to collect several papers together and take them all at once. We could
simply wait for all of the papers related to a single request, box them, and take
them on a single trip. We could box the entire response in the same way.
This is the approach that we'll take with the facade on our BBS example,
allowing us to dramatically reduce our round-trip communications. We'll use a
stateless session bean as a local client of our object model, instead of using the
EJB objects directly from a JSP or controller object. We'll wrap the important
public interfaces in the facade, called BoardFacade . Since this will be a stateless
session bean, we won't have a primary key class, but we will have home and
remote interfaces, a bean class, and a deployment descriptor.
The remote interface for BoardFacade
First, listing 8.4 contains the remote interface. We're collecting the methods
for accessing the BBS application here. Because we don't want to expose the
EJB entity bean implementation to our controller, our methods that return
boards, discussions, or posts return primitive object types, and our collections
return vectors. Otherwise, there are no surprises.
This facade provides three different ways to aggregate information in a sin-
gle round-trip: We can specify a longer parameter list, use a compound object
with many smaller atomic parts, or use a collection.
Search WWH ::

Custom Search