Java Reference
In-Depth Information
Table 1.1
Comparing classic EJB and POJO approaches (continued)
Classic EJB approach
POJO approach
Transaction management
EJB container-managed
transactions
Spring framework
Application assembly
Explicit JNDI lookups
Dependency injection
Don't worry if you are not familiar with all of these terms. In this section, I'll
examine each difference and explain and justify the POJO approach. You will see
how to develop business logic using the POJO approach. I use the money transfer
application from section 1.1.2 as an example.
1.2.1
Using an object-oriented design
Rather than structuring the money transfer example around methods such as
transfer() and its helper methods, the code should be structured around an
object model, which is a collection of classes that typically corresponds to real-
world concepts. For example, in the money transfer application, the object model
consists of classes such as Account , OverdraftPolicy , and BankingTransaction . In
addition, there is a TransferService that coordinates the transfer of money from
one account to another. Figure 1.2 shows the design.
TransferService
BankingTransaction transfer(fromId, toId, amount)
Banking
Transaction
Account
<<interface>>
OverdraftPolicy
date
balance
allow(Account, amount)
debit(amount)
credit(amount)
Transfer
Transaction
from
NoOverdraft
Policy
Limited
Overdraft
amount
to
Figure 1.2
An object model for the money transfer application
 
 
 
Search WWH ::




Custom Search