Java Reference
In-Depth Information
The Domain Model pattern is an excellent way to organize complex business
logic. However, there are situations where you might not want to use a domain
model, such as when the development team lacks the necessary OO design skills
to develop one or the business logic is very simple. It also does not make sense to
use a domain model when you cannot use a persistence framework because, for
example, the architecture does not include one or the application accesses the
database in ways that require it to use SQL directly. In these situations, you should
consider writing procedural business logic, an approach also known as the Trans-
action Script pattern.
In this chapter, we explore the benefits and drawbacks of using the Transac-
tion Script pattern, and describe how to implement this pattern using POJO s and
the Spring framework. You'll learn how to implement the procedural business
logic and database access logic in a way that makes them easier to develop, test,
and maintain. You'll also learn how to develop procedural business logic using a
test-driven approach that uses mock objects to implement the tests. We use the
Place Order use case as an example.
9.1 Overview of the Transaction Script pattern
The law of unintended consequences is that human actions always have unfore-
seen effects. Sometimes, these consequences are positive, such as the drug aspirin
preventing heart attacks. Other unforeseen consequences are negative or a
source of further problems, such as drugs with dangerous side effects and wind
farms that threaten migrating birds. Software technologies also have unexpected
consequences such as Tim Berners-Lee's hypertext system for sharing information
with particle physics researchers growing into the World Wide Web.
EJBs are intended to be a framework for building OO business applications. But,
ironically, one of its negative unintended consequences is that it has done a lot to
encourage procedural programming. As we saw in chapter 1, it's very common for
the business logic of a J2EE application to reside in the session beans instead of
being distributed among domain objects. Such a design is a perfect example of the
Transaction Script pattern. Each session bean method is what this pattern calls a
transaction script.
This pattern is widely used mainly because EJB 1 and EJB 2 made it easy to design
applications this way while making it difficult to use an OO approach. As a result,
the Transaction Script pattern is used even when inappropriate, which has led to all
kinds of problems. However, despite its drawbacks there are situations when this
 
 
 
 
Search WWH ::




Custom Search