[rules-dev] Justifying favorite colors

Geoffrey De Smet ge0ffrey.spam at gmail.com
Sun Jan 13 14:46:53 EST 2008


Conan and I had a discussion whether the current behavior of drools has 
a bug or a feature. What do you think?

Let's say I have a Person STATED fact:
  - Person: name=John, favoriteColor=RED
  - Person: name=Elvis, favoriteColor=GREEN
  - Person: name=Tom, favoriteColor=GREEN
Person has an equals/hashcode based on the name only.

I also have a logically asserted ExistingFavoriteColor
which just takes a color and has a equals/hashcode based on the color.

So now we have a rule which logically asserts all existing favorite colors:

rule "favoriteColor"
   when
     Person($color : favoriteColor)
   then
     insertLogical(new ExistingFavoriteColor($color));
end

So if we fire all rules the first time, there will be 2 existing 
favorite colors: RED and GREEN.

Next, John changes his mind, and has a new favoriteColor YELLOW.
When all rules are fired, what exisiting favorite colors would you expect?

a) YELLOW and GREEN because no one likes RED anymore
b) RED, YELLOW and GREEN because John used to like RED

-- 
With kind regards,
Geoffrey De Smet




More information about the rules-dev mailing list