Java Reference
In-Depth Information
3 Yes, that's a scary notion to me, too. The Spider-Man corollary applies: With Great Power Comes Great Respons-
ibility.
I'lldemonstrate asomewhat contrived buthopefullyamusingexample. Intheprevioussec-
tion I presented an application for managing accounts. Let me now assume that the account
manager, presumably some kind of bank, decides to get into the mortgage business. I now
need a class representing a mortgage application, which a client would submit for approv-
al. I'm also going to need a mortgage evaluator, which I'll implement both in Java and in
Groovy. The overall system is shown in figure 7.3 .
Figure 7.3. The GroovyEvaluator is a refreshable bean. The source code is deployed, and Spring checks it for
changes after each refresh interval. If it has changed, Spring reloads the bean.
To keep this example simple, the mortgage application class only has fields representing
the loan amount, the interest rate, and the number of years desired, as shown in the next
listing.
Listing 7.8. A trivial mortgage application class in Groovy
class MortgageApplication {
BigDecimal amount
BigDecimal rate
int years
}
As before, Groovy is used just to reduce the amount of code and to make it easier to work
with BigDecimal instances. An instance of this class is submitted to the bank, which
runs it through a mortgage evaluator to decide whether or not to approve it. The follow-
ing listing shows a Java interface representing the evaluator, which will be implemented in
both Java and Groovy.
 
 
Search WWH ::




Custom Search