Barry,
For your example, there would be no difference really, because Drools
detects that "putContract" is a pattern binding and that "strikePrice"
is a
field of "putContract". So, in your version number, it will automatically
generate a binding for the field and behind the scenes, it will behave
exactly like version 2.
Although, it is IMPORTANT to note that, if "putContract" was not a
pattern binding (for instance, it could be a field binding itself) or if you
had used deeper nested accessors, like "person.address.street", drools would
not be able to optimize and it would be more expensive to execute.
[]s
Edson
2008/6/5 Barry Kaplan <groups1(a)memelet.com>:
When the value of a property is compared across two instances, is it better
to create variables for the properties, or is using the object.property for
the comparison equivalent?
Here's an example: I need to match based on the strikePrice property. Is
either version better than the other?
version 1)
putContract : OptionInstrument(
optionType == OptionType.PUT)
callContract : OptionInstrument(
optionType == OptionType.CALL,
strikePrice > putContract.strikePrice)
// compare using navigation
version 2)
putContract : OptionInstrument(
optionType == OptionType.PUT,
putStrikePrice : strikePrice)
// delcare the variable
callContract : OptionInstrument(
optionType == OptionType.CALL,
strikePrice > putStrikePrice)
// compare using variable
--
View this message in context:
http://www.nabble.com/question-on-rule-efficiency-tp17672843p17672843.html
Sent from the drools - user mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @
www.jboss.com