Java Reference
In-Depth Information
When I started using EJB , I enthusiastically embraced the J2EE patterns for encap-
sulating the business logic: the Session Facade pattern and the DTO pattern. I duti-
fully wrote the session beans and DTO s and patiently waited for the application to
deploy in the EJB container. But as the applications I developed became more com-
plex, my frustration with this approach grew. Even though session beans provide
declarative transaction management and security, I found that the price for using
them was too high. I had to write large amounts of DTO code and session bean boil-
erplate methods that did very little of value. More important, development was
painfully slow because of the long build times and the lengthy edit-compile-debug
cycles. I was ready for a different approach.
After spending three days at The ServerSide Java Symposium 2004 learning
about such concepts as dependency injection and AOP , I decided it was time to try
the Spring framework. Spring offers many of the services provided by the EJB
framework but in a much more developer-friendly form. For example, with Spring
you just need to write a few lines of XML to make a POJO transactional. Spring
enables you to encapsulate your business logic with a POJO façade that you can
quickly and easily test within your IDE using regular JU nit tests. I discovered that
using the Spring framework dramatically increased my productivity.
Of course, if you are familiar with EJB then you might have a few questions.
How exactly are transactions managed? What about remote clients? How does
security work? In this chapter you will learn the answers to these and other ques-
tions. We examine the benefits and drawbacks of using a POJO façade and show
you when to use it to encapsulate a domain model. We also describe how to use
Spring to manage transactions and persistence framework connections. Finally,
you'll learn how to design, implement, and test a POJO façade using an example
façade from the Food to Go application.
7.1 Overview of a POJO façade
The modern car is a complex piece of machinery. It contains mechanical things
like pistons, cylinders, gaskets, and probably more computing power than was
used to send Neil Armstrong to the moon. Yet for the most part all of this com-
plexity is hidden from us. To make it go, all we interact with are a key, a steering
wheel, some pedals, and the gearshift lever. Those simple controls encapsulate
the complexity that is under the hood and elsewhere and make driving a car as
simple as possible.
For the same kinds of reasons that we must encapsulate the internal mecha-
nisms of a car, we often need to hide the complexity of the business logic from its
 
 
 
Search WWH ::




Custom Search