Drools规则可以具有多重继承吗

Drools规则可以具有多重继承吗

本文介绍了Drools规则可以具有多重继承吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对流口水并不陌生,并且熟悉使用extends关键字继承规则.问题有没有一种方法可以继承多个规则?这类似于在java类上使用多个接口.这是一个我希望它如何工作的示例,但是我在规则3上遇到了错误:

I am new to drools and am familiar with using the extends keyword to inherit a rule. Question is there a way to inherit multiple rules? This would be similar to using multiple interfaces on a java class. Here's an example of how I would expect it to work but I get an error on rule 3:

rule "rule 1"
when //person name == "John"
then //print "John"
end

rule "rule 2"
when //person last name == "Smith"
then //print "Smith"
end

rule "rule 3" extends "rule 1", "rule 2"
when //person age > 20
then //print John Smith is older than 20
end

推荐答案

我知道此线程很旧,但是可以执行以下操作:

I know that this thread is old but it's possible to do the following:

rule "first name is John rule"
    when
        $p : Person(  name == 'John' )
    then
end

rule "last name is Smith rule" extends "first name rule"
    when
        eval( $p.getLastName() == "Smith" )
    then
end

rule "age older than 20 rule" extends "last name rule"
    when
        eval ( $p.getAge() > 20 )
    then
        System.out.println($p.getFirstName() + " " + $p.getLastName() +
                " is older than 20");
end

rule "age younger than 20 rule" extends "last name rule"
    when
        eval ( $p.getAge() < 20 )
    then
        System.out.println($p.getFirstName() + " " + $p.getLastName() +
                " is younger than 20");
end

如您所见,您可以从超级规则继承其声明的变量来创建链式规则.

As you can see, you can create a chained rule from super rules inheriting their declared variables.

这篇关于Drools规则可以具有多重继承吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 11:36