Constants in rules

1,100 views
Skip to first unread message

Andy L

unread,
May 17, 2015, 2:53:52 AM5/17/15
to drools...@googlegroups.com
I have an interface class called "Constant" that I put all the constants in such as

String YES = "Yes"

in my rules, I have a lot of statements like

north == "Yes" && south == "Yes" && west == "Yes" && east == "Yes"

As you can see there are a lot of "Yes", I'd like to use the Constant class like so it's easy to change the values in the future if needed

$constant: Constant ( )

north
== $constant.YES

Is that possible?  If so

  • Can I declare $constant: Constant ( ) variable at the top of the drl file and use it or I have to declare it in each rule?
  • How can I insert the Interface class into the session?

Thanks








Wolfgang Laun

unread,
May 18, 2015, 9:24:37 AM5/18/15
to drools...@googlegroups.com


Am Sonntag, 17. Mai 2015 08:53:52 UTC+2 schrieb Andy L:
I have an interface class called "Constant" that I put all the constants in such as

String YES = "Yes"

in my rules, I have a lot of statements like

north == "Yes" && south == "Yes" && west == "Yes" && east == "Yes"

As you can see there are a lot of "Yes", I'd like to use the Constant class like so it's easy to change the values in the future if needed

$constant: Constant ( )

north
== $constant.YES

Is that possible?

No. But you can import the Constant type:

import some.pack.Constant;

and then use

north == Constant.YES

-W

 
Reply all
Reply to author
Forward
0 new messages