I am currently trying to implement an API for a conceptual model using Java interfaces and generics. The model (Transmodel V5.0) is described as an entity-relationship model in great detail, but it does not specify some of the base types used. For example the types of identifiers for the various entities or the types used to establish ordering in sequences are not defined.
Since I want to keep the API as generic as possible I started using generics to configure those details. I do not want to make any assumptions about the types, including not assuming that anything is consistent. Each entity can have a different identifier type, each sequence can have a different type used for ordering purposes.
The problem I am facing is that the complexity grows fast once one entity references another -- not only do I need to pass the types for its identifier, but also everything needed to configure the referenced entity.
For example I have:
/**
* @param <ID> The type for the identifier of this entity.
* @param <ID_JP> The type identifying journey patterns.
* @param <OP_JP> The ordering used for points in journey patterns.
* @param <JP> The type of journey pattern referenced by this entity.
*/
public interface VehicleJourney<
ID,
ID_JP, OP_JP extends Comparable<OP_JP>, JP extends JourneyPattern<ID_JP, OP_JP>
> extends IdentifiableObject<ID>
{
JP getJourneyPattern();
}
I can still read that and make sense of it, but it is getting more than a bit verbose. And then entities like the VehicleJourney can be referenced in other entities, which makes the type parameter list explode. This is pretty much the smallest non-trivial example I can think of.
Is there a way to create a single Java entity modelling the whole configuration of the type system? I am thinking of something that would have all the identifier types and ordering types attached and can then be passed around as one, turning the example above into something like this:
public interface VehicleJourney<CONF, JP extends JourneyPattern<CONF>>
extends IdentifiableObject<???>
{
JP getJourneyPattern();
}
In the spot with the question marks the type of the VehicleJourney identifier would have to be extracted from CONF somehow. If that would be feasible, then the complexity should stay at a manageable level.