How to avoid code duplication for one-off methods with a slightly different signature
- by Sean
I am wrapping a number of functions from a vender API in C#. Each of the wrapping functions will fit the pattern:
public IEnumerator<IValues> GetAggregateValues(string pointID, DateTime startDate, DateTime endDate, TimeSpan period) {
// Validate Data
// Break up Requesting Time-Span
// Make Requests
// Read Results (through another method call
}
5 of the 6 requests are aggregate data pulls and have the same signature, so it makes sense to put them in one method and pass the aggregate type to avoid duplication of code. The 6th method however follows the exact same pattern with the same result-set, but is not an aggregate, so no time period is passed to the function (changing the signature).
Is there an elegant way to handle this kind of situation without coding a one-off function to handle the non-aggregate request?