I came across an example of the implementation an an interface. Portion of code is
public partial interface IDataProvider
{
DataTable GetEmployeeAbsenceDurationTypes();
void AlterEmployeeAbsenceDurationTypes(DataTable lookUpTable);
}
public partial class DataProvider : IDataProvider
{
public DataTable GetEmployeeAbsenceDurationTypes()
{
return GetEmployeeAbsenceDurationTypes((DbTransaction)null);
}
public DataTable GetEmployeeAbsenceDurationTypes(DbTransaction tran)
{
//Db Operations
}
}
My first question is about this “DbTransaction” class. Its not in my project, is it a build in class?
My second question is, why in the DataProvider (the implementing class), the function is calling another overload of itself?
DbTransactionis a common base-class for representing database transactions in ADO.NET; each actual ADO.NET provider subclasses this (typically) – for exampleSqlTransaction : DbTransaction(the sql-server client).Calling an overload of self is a common way of implementing optional parameters, without code duplication prior to their addition in C# 4.0. In this case, that is essentially a pre-4.0 way of implementing:
either implementation (overloads or optional parameter) allows usage of the form: