I think you should rethink this structure.
The concept of an interface is that it enables 1 or many objects to be
treated in exactly the same way, however, the requirement of different
parameters means that it cannot treat these method calls in the same way, so
combining these method calls in an interface is pointless.
You could implement:
LoadRecord(object[] args);
Although I wouldn't recommend such a lack of type-safe arguments as a
consumer could pass 1 argument instead of two causing an IndexOutOfRange
exception.
You could implement
LoadRecord(string productCode);
LoadRecord(string orderNumber, string productCode);
// Impl 1
LoadRecord(string productCode)
{
// do stuff
}
LoadRecord(string productCode, string orderNumber)
{
LoadRecord(productCode); // ignore order number
}
Impl 2
// Impl 1
LoadRecord(string productCode)
{
throw new NotSupportedException();
}
LoadRecord(string productCode, string orderNumber)
{
// do stuff
}
But sooner or later Impl2 will be called with only 1 string firing the
NotSupportedException.
I'd recommend you modify this idea to some else, maybe:
LoadRecord(ILoadRecordInfo info)
Creating a new object that provides information about a request for loading
information, this can have an order number and product number etc.
HTH
"ABC" wrote:
Can I create an Interface which have a method have variate type parameters?
I want create an Interface named IDataEditable which have two methods:
LoadRecord and SaveRecord.
As the LoadRecord have variate type parameters based on the record primary
key definition such as:
The product table should be:
LoadRecord(string productCode)
The OrderDetail table should be:
LoadRecord(string OrderNo, string ProductCode)
Should I write the code as follow?
interface IDataEditable
{
void LoadRecord();
void SaveRecord();
}