[rules-users] Subclasses matche superclasses problem.

Marcus Ilgner marcus.ilgner at gmail.com
Fri Feb 16 10:40:05 EST 2007


Hi Oana,

On 2/16/07, nicolae oana <oananicolae1981 at yahoo.com> wrote:
> Hi everybody,
>
> I have a class Car which is superclass for class ConvertibleCar, two rules
> (described below) and a ConvertibleCar fact in working memory that causes
> both rules to fire, resulting this way an unwanted change to the car`s
> attribute and an infinite loop.
>
> How do I evitate this problem: the specialization class fact to not match
> its superclass column in a rule?
>
> ConvertibleCar car =new ConvertibleCar(10000);
>
> rule "rule-1"
>     when
>        $car:Convertible()
>     then
>    $car.setPotentialTheftRating("high");
> end
>
> rule "rule-2"
>     when
>         $car:Car(price<20000)
>      then
>     $car.setPotentialTheftRating("low");
>  end
>
> Best regards, Oana
>

I'd say that this behaviour is correct in principle. If you want to
avoid this, you could add further constraints in the rules concerning
the superclass:

rule "rule-2"
    when
        $car:Car(price<20000, class != Convertible.class)
     then
    $car.setPotentialTheftRating("low");
 end

I'm not sure if this works exactly like that (don't have a Drools
installation at hand), but  I guess you get the idea.

Best regards
Marcus



More information about the rules-users mailing list