I have method calls that take different inputs, i.e:
public Authors GetAuthors(string name, string sortBy, string sortDir, int startRow, int numRow)
{
// Get authors based on filters
}
public Books GetBooks(string id, string year, string sortBy, string sorDir, int startRow, int numRow)
{
// Get books based on filters
}
I’m planning to change it so that the filters are objects, i.e:
public Authors GetAuthors(GetAuthorsFilters filters)
{
// Get authors based on filters
}
public Books GetBooks(GetBooksFilters filters)
{
// Get books based on filters
}
But many filters are common across the methods, and I would like to build an generic interface for this (i.e IFilter) that can take different filter objects, but not sure where to start. Any suggestion or recommendation?
Thanks.
In my opinion, I’d use an abstract class to complish what you are looking for. You could create an interface for each search type, but then you have to implement the interface everytime, and it appears that there isn’t a programatic difference between your shared properties in BookFilters and AuthorFilters. Maybe something like: