j-easy / easy-rules

The simple, stupid rules engine for Java
https://github.com/j-easy/easy-rules/wiki
MIT License
4.91k stars 1.06k forks source link

Is it possible to inherit the RuleProxy class to be able to override getRuleName method ? #299

Closed sverin closed 4 years ago

sverin commented 4 years ago

Since the RuleProxy class has a private constructor there is no way that I can inherit and override that class. There are a reason for that I'm sure. But I would like to override the method getRuleName and only that method.

I can do my own implementation of the proxy by copying it and just change that method. That works since I tried it. But there is a lot of code to copy just for one small change. Is there a better way that this can be accomplished ?

sverin commented 4 years ago

The issue I had was that I could have multiple instances of the same rule but with different values. For example I have multiple price rules saved in a db. But only one PriceRule class. But their properties defines if it evaluates to true. The normal Rules class had a TreeSet implemented and then only one rule instance got registered since they hade the same rule name defined in the annotation. However, by extending the Rules class and using an ArrayList I achieved what I wanted.

zhhaojie commented 4 years ago

@sverin hi, let's make it simple.