There is a collection class with the get
method, which, depending on the parameters passed, can return an instance of one of the three classes. The only thing in common between classes is that they can all be in this collection.
How from the point of view of architecture it is better to solve this problem?
- Inherit all three classes from the same abstract, so that the user himself checks the type and castile.
- To do as in
StreamTokenizer
: get anEnum
with three values, and agetType()
function that returns thisEnum
. The user callsgetType
and, depending on the result, gets the value using one of the threegetLast*TypeName*
functions. - Own option.