Java Reference
In-Depth Information
Because Groovy has operator overloading, however, none of that is necessary. I can simply
declare the balance to be a BigDecimal , and everything else just works, even if I use the
Account class from Java.
One additional comment about the Account : at the moment no constraints are being ap-
plied to ensure that the balance stays positive. This is as simple as I can make it, just for
exposition purposes.
The overall design for using the Account class is shown in figure 7.2 . This is a very
simple form of a layered architecture, with transactional support in the service layer and a
persistence layer that consists of an interface and a DAO class, discussed shortly.
Figure 7.2. A simple account management application. Transactions are demarcated in the service layer. The
persistence layer consists of a single DAO class that implements an interface and uses the Spring JdbcTemplate to
access an embedded database.
The persistence layer follows the normal Data Access Object design pattern. The next list-
ing shows a Java interface, called AccountDAO , written in Java.
Listing 7.2. The AccountDAO interface, in Java
package mjg.spring.dao;
import java.util.List;
import mjg.spring.entities.Account;
public interface AccountDAO {
int createAccount(double initialBalance);
Account findAccountById(int id);
List<Account> findAllAccounts();
void updateAccount(Account account);
void deleteAccount(int id);
}
 
Search WWH ::




Custom Search