2017-09-19 10 views
0

私は5つのファクトタイプBaseFact、AFact、BFact、CFact、DFactを持っています。Dorols Instanceof with Inheritance

AFact、BFact、CFactおよびDFactはすべてBaseFactから継承しています。

私は、もはやCFactsやDFactsで実行できないBaseFactsで動作するいくつかのルールを持っています。

BaseFactルールがBaseFact、AFacts、BFactでのみ実行されるように、BaseFactルールを変更する最良の方法は何ですか?

私は次のように確認できるinstanceOf関数がありますか?

rule "BaseRule" 
    when 
     fact : BaseFact(this instanceOf AFact || this instanceOf BFact) 
     ... 
    then 
     ... 
end 

また、このルールをAFactとBFactの2つの新しいルールに分割する必要がありますか?

答えて

0

instanceOf演算子がない場合でも、探しているものを達成するにはいくつかの方法があります。

rule "BaseRule" 
when 
    fact : BaseFact(class == AFact.class || == BFact.class) 
    ... 
then 
    //note that the variable fact is still of type BaseFact 
    ... 
end 

厄介バージョン:

rule "BaseRule" 
when 
    fact : BaseFact() 
    not CFact(this == fact) 
    not DFact(this == fact) 
    ... 
then 
    //note that the variable fact is still of type BaseFact 
    ... 
end 

または:

rule "BaseRule" 
when 
    AFact() OR 
    BFact() 
    ... 
then 
    //note you can't bind a variable to AFact or BFact 
    ... 
end 

あなただけにした、あなたが一致させたい2つの具体的な種類を持っている場合は

これら

はいくつかのアイデアです2つの個別のルールは悪い考えのようには聞こえません。 BaseFact(this.class == AFact.class || this.class == BFact.class) `私がなってしまった何だった:

+0

'実際、それがお役に立てば幸いです。 – Jamie