Reputation:
I would like to implement a interface and repository pattern. My different repositories can have type data types,
First one is (String-int, char-long)
Second one is (Char-double, double-string). Pattern keeps going, we have around 50 different methods.We are changing our interface/repositories to another database system, etc.
How would I edit the edit the interface below, to allow different data types? Thanks,
public interface ITransactionRepository
{
void SearchTransactionbyCategoryCustomerId(Category, CustomerId ); // what should I write here?
void SearchTransactionbyProductDepartment(Product, Department);
......
}
public class TransactionRepository1: IRepository
{
void SearchTransactionbyCategoryCustomerId(string Category, int CustomerId);
void SearchTransactionbyProductDepartment(char Product, long Department);
......
}
public class TransactionRepository2: IRepository
{
void SearchTransactionbyCategoryCustomerId(char Category, double CustomerId);
void SearchTransactionbyProductDepartment(double Product, string Department);
......
}
Upvotes: 0
Views: 226
Reputation: 2801
Define your interface as generic and specify the actual types in the implementation,
public interface ITransactionRepository<TCategory, TCustomerId, TProduct, TDepartment>
{
void SearchTransactionbyCategoryCustomerId(TCategory Category, TCustomerId CustomerId );
void SearchTransactionbyProductDepartment(TProduct Product, TDepartment Department);
......
}
public class TransactionRepository1: ITransactionRepository<string, int, char, long>
{
void SearchTransactionbyCategoryCustomerId(string Category, int CustomerId);
void SearchTransactionbyProductDepartment(char Product, long Department);
......
}
public class TransactionRepository2: ITransactionRepository<char, double, double, string>
{
void SearchTransactionbyCategoryCustomerId(char Category, double CustomerId);
void SearchTransactionbyProductDepartment(double Product, string Department);
......
}
Upvotes: 1