清單 3. MortgageQualificationResult 類
public class MortgageQualificationResult {
private boolean qualified;
private double interestRate;
private String message;
private String productName;
// .. Standard setters and getters not shown.
}
腳本設置 result 的屬性,從而指出貸款人是否符合抵押貸款的要求以及應該采用的利率。腳本可以通過 message 和 productName 屬性指出導致貸款人不合格的原因和返回相關的產品名稱。
腳本文件
在給出 ScriptMortgageQualifierRunner 的輸出之前,我們先看看這個程序運行的 Groovy、JavaScript 和 Ruby 腳本文件。Groovy 腳本中的業務邏輯定義了一種條件相當寬松的抵押產品,同時由于金融風險比較高,因此利率比較高。JavaScript 腳本代表一種政府擔保的抵押貸款,這種貸款要求貸款人必須滿足最大收入和其他限制。Ruby 腳本定義的抵押產品業務規則要求貸款人有良好的信用記錄,這些人要支付足夠的首付款,這種抵押貸款的利率比較低。
清單 4 給出 Groovy 腳本,即使您不了解 Groovy,也應該能夠看懂這個腳本。
清單 4. Groovy 抵押腳本
/*
This Groovy script defines the "Groovy Mortgage" product.
This product is relaxed in its requirements of borrowers.
There is a higher interest rate to make up for the looser standard.
All borrowers will be approved if their credit history is good, they can
make a down payment of at least 5%, and they either earn more than
$2,000/month or have a net worth (assets minus liabilities) of $25,000.