I have a requirement where I need to send SMS to our customers. For sending SMS we have multiple providers. To achieve this, I have designed an interface and created different classes for providers by implementing this interface
public interface IProvider
{
Task<bool> SendAsync(ProviderRequest providerRequest);
}
public class Provider1: IProvider
{
public async Task<bool> SendAsync(ProviderRequest providerRequest)
{
//call provider1
return somethingBool;
}
}
public class Provider2: IProvider
{
public async Task<bool> SendAsync(ProviderRequest providerRequest)
{
//call provider2
return somethingBool;
}
}
We want to extend the requirement to get back the response from the provider. Now, to implement this I can think of 2 ways.
ProviderResponse
object and map the response to it and return.public interface IProvider
{
//Updated interface method just to be concise, this will be a new version of the method
Task<ProviderResponse> SendAsync(ProviderRequest providerRequest);
}
// response class
public class ProviderResponse
{
public bool IsSuccess { get; set; }
public string ProviderResponse { get; set; }
}
public interface IProvider
{
Task<bool> SendAsync(ProviderRequest providerRequest);
string ProviderResponse { get; }
}
Which design I should go with? Where will be the best places to use these design solutions?
Seem the First approach look more valid.
IProvider
require one more function to expose which have a different response and different parameter. Then in the Second approach IProvider
becomes a design issue, ProviderResponse
output is responsible for which function.So overall feel, the First approach looks more valid in terms of Thread Safe, Design, Performance, and extendable.