Java Reference
In-Depth Information
Listing 7.9. The Evaluator interface in Java
public interface Evaluator {
boolean approve(MortgageApplication application);
}
The interface contains only one method, approve , which takes a mortgage application as
an argument and returns true if the application is approved and false otherwise.
Pretend now that it is currently the summer of 2008. The general public is blissfully un-
aware of terms like credit default swaps , and banks are eager to loan as much money as
possible to as many people as possible. In other words, here's a Java implementation of the
Evaluator interface.
Listing 7.10. A Java evaluator, with a rather lenient loan policy
public class JavaEvaluator implements Evaluator {
public boolean approve(MortgageApplication application) {
return true;
}
}
That's a very forgiving loan policy, but if everyone else is doing it, what could go wrong?
What went wrong, of course, is that in the late summer and early fall of 2008, Bear Stearns
collapsed, Lehman Brothers went bankrupt, and the U.S. economy nearly collapsed. The
bank needs to stop the bleeding as soon as possible. If the evaluator in place is the Java
evaluator just shown, then the system has to be taken out of service in order to modify it.
The fear is that if the system is taken offline, then customers might worry that it will never
come back again. [ 4 ]
4 That's an It's a Wonderful Life reference: “George, if you close those doors, you'll never open them again!”
There's another possibility, however. Consider the Groovy version of the mortgage evalu-
ator, whose behavior is equivalent to the Java version, as shown in the following listing.
Listing 7.11. A Groovy mortgage evaluator deployed as source code
class GroovyEvaluator implements Evaluator {
boolean approve(MortgageApplication application) { true }
}
 
Search WWH ::




Custom Search