SpineEventEngine / core-java

The Java implementation of the framework core
https://spine.io
Apache License 2.0
36 stars 12 forks source link

Allow optional `@React` annotation of `Policy.whenever()` methods #1540

Open alexander-yevsyukov opened 1 year ago

alexander-yevsyukov commented 1 year ago

I've just tried to create a couple of stub Policy classes and forgot to add @React annotation on the implemented whenever() methods. This resulted in runtime exception pointing that the contract for the methods is not correct.

We can make it more convenient for the user, making the @React annotation optional in this case (just for the additional clarity). Here's why:

  1. The Policy class assumes that there is only one even handled by it. We don't need to find annotated methods to see what signals a class handles. We know there's gonna be only one. We even check for this on runtime.

  2. The method whenever() is abstract. We know it's going to be overridden. We know the event type handled by the policy by the generic parameter of the class (and the method). Why force the annotation?

alexander-yevsyukov commented 1 year ago

There is a GreedyPolicy test env. class in ProtoData code with the associated test. It should be migrated to core-java as an additional result of this issue.