Hi,
For the v12.0 orekit I have a suggestion for a new way of managing overloading/dispatch. In java there is possibility to have several methods with different types and same name while this is not possible in python in same way. Note that this is only a topic when subclassing java classes in Python, so quite advanced usage.
Previously this has been solved by adding some extra characters to the method names highlighting the different types like _FFA for three parameters. This gives clear entry point for each java method in python and ensures that all combinations are implemented in the subclass.
However, when working with orekit v12 it becomes clear that this is quite a quirky method when we have methods with lots of overloads.
With some tests confirming that it works, I am suggesting that all these overloaded methods will call same ptyhon method and that that method needs to take care of knowing which type of response is expected. This is a bit of overhead in the python class, but i find it less quirky and more clean.
For example:
class TestGroundPointing(PythonGroundPointing):
def getTargetPV(self, pvProv, date, frame) -> TimeStampedPVCoordinates|TimeStampedFieldPVCoordinates:
if isinstance(pvProv, FieldPVCoordinatesProvider):
return TimeStampedFieldPVCoordinates(date, FieldPVCoordinates.getZero(date.getField()))
elif isinstance(pvProv, PVCoordinatesProvider):
return TimeStampedPVCoordinates(date, PVCoordinates.ZERO)
else:
raise RuntimeError(f'Not supported type of PVCoordinatesProvider: {type(pvProv).__name__}')
There are 3rd party libraries to support this type of problems as well, like multipledispatch which gives a quite clean code:
from multipledispatch import dispatch
class TestGroundPointing(PythonGroundPointing):
@dispatch(PVCoordinatesProvider, AbsoluteDate, Frame)
def getTargetPV(self, pvProv, date, frame) -> TimeStampedPVCoordinates|TimeStampedFieldPVCoordinates:
return TimeStampedPVCoordinates(date, PVCoordinates.ZERO)
@dispatch(FieldPVCoordinatesProvider, FieldAbsoluteDate, Frame)
def getTargetPV(self, pvProv, date, frame) -> TimeStampedPVCoordinates|TimeStampedFieldPVCoordinates:
return TimeStampedFieldPVCoordinates(date, FieldPVCoordinates.getZero(date.getField()))
In previous versions this has been implemented by a second method in the Python class called “getTargetPV_FFF” for the Fields version.
Let me know if you have any thoughts or issues with this change?