I have an Interface
interface IRepository<T>
{
List<T> GetAll(string id)
List<T> GetAll(string id, string desc)
List<T> GetAll(string id, string desc, int[] status)
List<T> GetAll(string id, string desc, int[] status, ....)
}
Many of my classes were implementing this interface. My problem is, more often, when clients request customization, I usually need to add parameters on the methods. So when I have 10 classes implementing this interface, i also need to update each of the classes inherinting the interface (I'm using abstract factory pattern) which is quite hassle. And it also not very pleasing to the eye seeing many method overloading like the example above, imo. Is there any solution/work around to make the parameters dynamic (beside to the param [] option which I don't like). I mean like a dedicated class/interface parameter so that i dont need to overload the method when i'm adding parameter. SOmething like this
interface IRepository<T>
{
List<T> GetAll(Parameter args);
}
the Paramter class (or maybe interface)
static class Parameter
{
public string Id { get; set; }
public string Desc { get; set; }
public int[] Status { get; set; }
}
sample implementation by clients
class Client1Accounts : IRepository<Employee>
{
List<Employee> GetALl(Parameter param)
{
return DataFactory.GetAllById(param.Id);
}
}
class Client2Accounts : IRepository<Employee>
{
List<Employee> GetALl(Parameter param)
{
return DataFactory.GetAllByDesc(param.Desc);
}
}
class Client2Accounts : IRepository<Employee>
{
List<Employee> GetALl(Parameter param)
{
int[] status = { 99, 88 }
return DataFactory.GetAllFiltered(param.Id, param.Desc, status);
}
}
In this way, when I need to add parameter, I'll just have to add another property to the Parameter Class
static class Parameter
{
public string Id { get; set; }
public string Desc { get; set; }
public int[] Status { get; set; }
public long newLongParam { get; set; }
}
Is this approach correct? any other ideas?