TLDR: I have three subclasses, each inherits from the same parent class, each defines an identical method that does almost the same thing, except that each of these methods has a different return type. The return type does not affect the logic of the method in any way. To get rid of this repetition, I want to be able to define a single method in the parent class that each of the child classes can use - but how, when I need this method to be able to return three different types?
Background: I have three different GUI components - each of them is designed to display information about a different algorithm, and each of them has a "RunAlgorithm" button and a "LaunchAnimation" button (and identically named controller methods). An EgGivenData object can be passed into the components, and in each component, depending on fields in the EgGivenData object, the displayed information varies and buttons are either activated or greyed out.
The RunAlgorithm and LaunchAnimation methods are called on the concrete types in response to ActionEvents when the button of the associated component is clicked.
Each of these GUI Components is associated with a different algorithm, but the components mostly do the same thing and share a lot of logic, so each component inherits from the same abstract class. The purpose of the algorithms is to convert the EgGivenData into animation data - each algorithm does this in a slightly different way. The LaunchAnimation button in each component passes the data outputted by the algorithm into an "AnimateResults" method.
The Problem:
My problem is this: each of the algorithms returns an OutputData array of a different data type. Therefore, even though the "LaunchAnimation" method does pretty much the same thing for each component, I've had to implement it separately for each component, each time with a different return type.
My initial solution was this: just encapsulate the three different OutputData arrays into three different types, each of which inherits from the same interface. The LaunchAnimation method can then have this interface as its return type, and the AnimateResults method can take the interface as a parameter, and act on each sub-type differently using polymorphism.
So I started making the interface, but then I realised it would need getData and setData methods, so I will need to specify the return type for the getData method in the interface. However, I need each class which implements the interface to have a getData method with a different return type. So the only solution is to create an empty interface, each of the subclasses will have to define their own getData and setData methods, and this will allow me to pass the encapsulated data from one method to another. But using an empty interface seems like bad programming.
(I'm using Java, following an Model-View-Controller architecture in JavaFX. When I say component, I mean an FXML view with an associated controller. I'm currently trying to implement the model, leading into the problems outlined above.)
java.util.List<E>
has a methodE get(int index)
where <E> is the different returntype