I'm having trouble deciding how to design this service API.
public class GetCurrentValuesRequest
{
public int ReferenceID { get; set; }
public int[] FilterIDs { get; set; }
}
public class GetDefaultValuesRequest
{
public int[] FilterIDs { get; set; }
}
public class GetValuesAsOfDateRequest
{
public int ReferenceID { get; set; }
public int[] FilterIDs { get; set; }
public DateTime AsOf { get; set; }
}
public class GetValuesAsOfChangeSetRequest
{
public int ReferenceID { get; set; }
public int[] FilterIDs { get; set; }
public long ChangeSetIDs { get; set; }
}
public class GetProposedValuesRequest
{
public int ReferenceID { get; set; }
public int[] FilterIDs { get; set; }
public long ApprovalKey { get; set; }
}
public class GetValuesIfModifiedRequest
{
public int ReferenceID { get; set; }
public int[] FilterIDs { get; set; }
public DateTime Since { get; set; }
}
public class GetValuesResponse
{
public string[] Results { get; set; }
}
public class GetValuesIfModifiedResponse
{
public string[] Results { get; set; }
public bool IsModified { get; set; }
}
public interface IService
{
GetValuesResponse GetValues(GetCurrentValuesRequest request);
GetValuesResponse GetValues(GetDefaultValuesRequest request);
GetValuesResponse GetValues(GetValuesAsOfDateRequest request);
GetValuesResponse GetValues(GetValuesAsOfChangeSetRequest request);
GetValuesResponse GetValues(GetProposedValuesRequest request);
GetValuesIfModifiedResponse GetValuesIfModified(GetValuesIfModifiedRequest request);
}
I've thought about changing it to have make the IfModified
request / response subclasses of the simple GetValues
request response and only including one GetValues
call. The server would return a different response depending on the input request, but that requires user to call IService
this:
var response = (GetValuesIfModifiedResponse)serviceClient.GetValues(new GetValuesIfModifiedRequest() { ... });
I've also thought about placing IsModified
in the simple GetValuesResponse
, and only populating it if a GetValuesIfModifiedRequest
is passed into it. But that seems a bit strange to include it in a result from a method which does not actually do anything with it. Also, it might throw of a user if they see it and expect to be able to use it in their code. bool? IsModified
is better, but I'm not entirely sold on it just yet.
Any suggestions for how to best design this API?
IsModified
tofalse
if the response is not modified? I don't see a good reason to provide two different responses.IsModified == false
may not be accurate. In fact the use case for this property isif (response.IsModified) { refreshCache(); }
so if the service is not called correctly, the cache would never get refreshed.IsModified == false
then theResults
array is empty. SoIsModified
provides extra information about the state of the system. I'd rather haveIsModified == null
indicate that no such checks were made.