I have a number of class where the first thing I have to do in the methods is retrieve the value of a variable from an external system.
class One {
ExternalService externalService;
public void method1() {
var field = externalService.getValue();
// do something with field
}
}
class Two{
ExternalService externalService;
public void method2() {
var field = externalService.getValue();
// do something with field
}
}
I think this functionality could extract it to an aspect and get the value of field. I have seen that you could make use of @Around. But my doubt is that once the field value is retrieved in the aspect, how do I return it to method1, method2 so that these methods can use the variable?