To answer your specific questions, the answer is no. You cannot create your own classes and use them in Rules DSL. There is no global context somewhere. Well, that last part isn’t strictly true. You do have access to a global context: Items.
There are lots of ways you can declare constants:
- global vars
- a .map file and the transform Action, see Design Pattern: Human Readable Names in Messages
- Design Pattern: Encoding and Accessing Values in Rules
Depending on the nature of your repeated code, there are a many techniques that can be used to avoid that.
I’m tired of retyping this so I wrote a DP: Design Pattern: DRY, How Not to Repeat Yourself in Rules DSL. It’s more of a meta-DP since everything is already documented in DPs and tutorials but people are either not finding them or not looking for them.