IDE : VS 2008,
Platform : .NET 3.5, Hi,
I typically dont create interfaces unless i have to, however in my current application i have to create interfaces in the Data access layer. I'm a in a minor confusion that hwo do i create those interfaces more how to implement them:
the following code might make things clear:
I have the following class and interface in the data access namespace |
using ConsoleApplication8.BusinessLayer; using
ConsoleApplication8.DataAccessLayer ; using System.Data ; using System
;
Namespace DataAccessLayer
{
Public Class CountryGateway :
ICountryGateway { public
void InitCountry()
{
//write
code
}
public
Int32 saveCountry(ByRef obj As Country)
{
//write
code
}
// //implementation
for other methods SearchByIndex() SearchByName and
UpdateCountry() // //
}
Interface
ICountryGateway { void
InitCountry() ; Int32
saveCountry(ref obj As
Country) ; DataSet
SearchByIndex(countryNo As
String) DataSet
SearchByName(countryName As
String); Int32
updateCountry(ref country As
Country); }
}
Namespace
BusinessLayer {
Public Class Country
{
}
}
|
1. Is this way implement the interface in the data access layer? (in this case the class CountryGateway access the database.) i.e: That we should create interfaces to access DB in the DAL and then we should also write the implementation for those interfaces in the DAL?
2. I have been told that we should create interfaces than abstract classes espcially in the data access layer, is there a particular reason for this?