There are currently 3 ways to write your accumulate pattern in drools:
- The way you have pointed out containing all the different sections: init, action, reverse and result. The problem with this syntax is that you have to embed java code in your rules making them hard to read and maintain. Following this syntax, if you want to reuse an accumulate function you have to copy and paste it. This form of accumulate is highly discouraged by drools team.
- Use some of the predefined accumulate functions like sum(), avg(), count(), etc.
- If the predefined set of accumulate functions is not enough you can create your accumulate function in a Java class and then register it in drools and use it in your DRL. Please refer to the documentation for further information.
Best Regards,