16.3. DRL 中的功能
DRL 文件中的功能将语义代码放在规则源文件中,而不是在 Java 类中。如果规则中的某个部分被重复使用,
并且每个规则的参数不同,则功能特别有用。在 DRL 文件中的规则上方,您可以声明函数或导入帮助程序类的静态方法作为功能,然后在规则的操作( then )部分中按名称使用函数(then
)。
以下示例演示了在 DRL 文件中声明或导入的功能:
带有规则(选项 1)的功能声明示例
function String hello(String applicantName) { return "Hello " + applicantName + "!"; } rule "Using a function" when // Empty then System.out.println( hello( "James" ) ); end
使用规则导入功能示例(选项 2)
import function my.package.applicant.hello; rule "Using a function" when // Empty then System.out.println( hello( "James" ) ); end