I am trying to refactor my code. Currently I have different method names for similar kind of funcitonality as shown below.
public interface IReminderService
{
Task GenerateInviteReminders(string executedBy);
Task GenerateBookingReminders(string executedBy);
}
But want to use something like below. But not sure how to pass parameters in switch case to set the strategy. The interfaces are injected using IOC. Or please let me know the correct way to refactor my code.
public interface IReminderStrategy
{
Task GenerateReminders(string executedBy);
}
public class StrategyA : IReminderStrategy
{
public StrategyA(IInterfaceA a, IInterface b)
{}
}
public class StrategyB : IReminderStrategy
{
public StrategyB(IInterfaceA a, IInterface b)
{}
}
public class ExampleService {
private readonly IInterfaceA _a;
private readonly IInterfaceB _b;
public ExampleService(
IInterfaceA a,
IInterfaceB b
) {}
switch case(string messageType)
{
IReminderStrategy strategy;
case "A":
strategy = new StrategyA(?????)
break;
case "B":
strategy = new StrategyB(?????)
break;
}
}
Aucun commentaire:
Enregistrer un commentaire