Java Reference
In-Depth Information
A (programmatic) client would use the banking system by invoking methods on the service
class,
AccountService
, which presumably would be transactional. The service class
usesimplementationsofthe
AccountDAO
interfacetoworkwithindividualaccounts.The
Account
class itself is a simple POJO.
The next sections show the implementation code for the service and DAO, and illustrate
how to use coerced closures and expandos to represent dependent objects. Specifically,
when testing the logic in the service class a closure is used to represent the DAO. When
testing the DAO implementation an expando stands in for the
File
class.
6.3.1. Coerced closures
Let me start with the
AccountService
, as shown in the next listing.
Listing 6.16.
AccountService
(in Java): uses the
AccountDAO
to find
Accounts
Again, to keep things simple, the
AccountService
has only two business methods:
a
transferFunds
method to move money from one account to another, and a
get-
Balance
method that delegates to the corresponding method in
Account
. Both methods
take integer
id
s as arguments and use the
AccountDAO
to look up the corresponding ac-