I was recently working on an application and have a use case where I return back a set of responses to clients e.g. ALLOW, DENY and PENDING.
Let's say if the response returned by the service is PENDING, I want clients to retry back after a given interval. This interval is given by the Server.
I want to know what are best practices around modeling my service response for such a use case. I was thinking to have the response something like this:
String Decision; long retryIntervalInMinutes;
but then for decision ALLOW and DENY, retryIntervalInMinutes doesn't makes sense and should not be returned.
One way to model this:
Decision - Abstract class Allow extends Decision Deny extends Decision Pending extends Decision
Only Pending object will contain the retryIntervalInMinutes.
But this comes with its own problems as how client will decipher such a response without using instanceof or type casting etc.
Or is there any other better way to model such a response ?