[Refactor] Replace Proxy.reactTo() with method level @React
nbrugger-tgm opened this issue · comments
The way to specify custom methods to react to is a little cumbersome and error prone.
Before
ReactiveProxy<Person> person = ReactiveProxy.createProxy(Person.class);
person.setStrategy(REACT_ON_CUSTOM);
person.reactTo(
"updateHealthStatus",
"setAge"
);
After
@ReactTo(ANNOTATION);
public class Person {
@Reactive
public updateHealthStatus(ECard card){
....
}
@Reactive
public setAge(int age){
...
}
}
Alernative
public class Person {
@Reactive
public updateHealthStatus(ECard card){
....
}
@Reactive
public setAge(int age){
...
}
}
ReactiveProxy<Person> person = ReactiveProxy.createProxy(Person.class);
person.setStrategy(ANNOTATIONS);
Requirement
@ReactTo
should take theese options
NOTHING
- while useless on first glance in complex structure it maybe makes senseANNOTATED
- just annotated methodsSETTER
- self explanatoryALL
- self explanatory
Adaptation
Due to #39 #44 #38 and #45 the creation process of proxies changed and therefore a new approach is needed!
Design
We will go with the following approach
Owned classes
public class Person {
@Reactive
public updateHealthStatus(ECard card){
....
}
@Reactive
public setAge(int age){
...
}
}
ProxyCreator creator = ProxyCreator.besideOrigin();
creator.setStrategy(ANNOTATIONS);
ReactiveProxy<Person> person = creator.createProxy(new Person());
Or for 3rd party classes
ProxyCreator creator = ProxyCreator.custom(getClass());//custom is the best for 3rd party
creator.setStrategy(SETTERS);
//or
creator.setStrategy(byName("update","erase"));
ReactiveProxy<Matrix> person = creator.create(new Matrix());
Released in v4.0.0b8