How to avoid code duplication for one-off methods with a slightly different signature
Posted
by Sean
on Stack Overflow
See other posts from Stack Overflow
or by Sean
Published on 2010-03-30T17:46:06Z
Indexed on
2010/03/30
17:53 UTC
Read the original article
Hit count: 396
.NET
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?
© Stack Overflow or respective owner