I am designing an API. Here are some example methods from an interface:
Entry findEntry(int processId);
Entry findEntry(int processId, Filter filter);
where processId refers to some unique identifying information. However I don’t really know what the type of processId is yet.
How can I abstract away an element like id of something?
The best I could come up with is creating a dummy interface:
Entry findEntry(ProcessId id);
Entry findEntry(ProcessId, Filter filter);
However, I worry that with the above approach I may force the client of the API to operate on too high an abstraction level. For example, the equality of process id’s will no longer work (whereas if they used int’s – it would).
Clarification: I failed to clarify that I am writing only the interfaces (contracts), to be implemented later, possibly by a different team. That is why I cannot enforce certain things like equals method.
Generics is your friend here
on the method itself if appropriate
or possible the class
Edit: If you’re defining the interface, you can also define this there and leave it to the implemntors of the interface to figure out what type they want to use to identify an Entry.
Usage: