I am exploring different ways to create a simple business rule engine in Java. I need to present the client with a simple webapp that lets him configure a bunch of rules. A
A simple rule engine can be build upon closures, i.e in Groovy:
def sendToOutPatient = { ... };
def sendToInPatient = { ... };
def patientRule = { PATIENT_TYPE ->
{'A': sendToOutPatient,
'B': sendToInPatient}.get(PATIENT_TYPE)
}
static main(){
(patientRule('A'))()
}
You could define your rules as closures, reuse/reassign them or even build a DSL over them.
And Groovy can be easily embedded into Java, example:
GroovyShell shell = new GroovyShell(binding);
binding.setVariable("foo", "World");
System.out.println(shell.evaluate("println 'Hello ${foo}!';));