I have a Model which Implements 3 different interfaces
public class CustomerRateSettingModel : IBaseFactory, IHandleSearch, IHandleSearchAggregate
I am very new with implementing design patterns and trying to implement Factory pattern to create instances. But I am unable to find a proper way to avoid the identical Switch statements while writing Factory
public static IHandleSearch GetClassInstanceForSearch(string className)
{
switch (className.ToLower())
{
case "customerratesettingmodel":
return new CustomerRateSettingModel();
default: return null;
}
}
private static IBaseFactory ManufactureModel(string className)
{
switch (className.ToLower())
{
case "customerratesettingmodel":
return new CustomerRateSettingModel();
default: return null;
}
}
Is there is any right way to handle scenarios like that?
Aucun commentaire:
Enregistrer un commentaire