I have 3 classes in Data Access project, and all 3 classes have many data access methods ( GetSomeList
, InsertSomeData
, UpdateSomeData
…).
All 3 classes have several methods that are same.
I don’t want to write same methods 3 times.
What is best approach here?
One possible solution would be to define one common class that will be inherited. Is this good approach?
Example:
public abstract class CommonDataLayer
{
public int CommonMethod()
{
Random random = new Random();
int randomNumber = random.Next(0, 100);
return randomNumber;
}
}
public class FirstDataLayer : CommonDataLayer
{
public int FirstMethod()
{
return CommonMethod() + 1;
}
}
public class SecondDataLayer : CommonDataLayer
{
public int SecondMethod()
{
return CommonMethod() + 2;
}
}
public class ThirtDataLayer : CommonDataLayer
{
public int ThirtMethod()
{
return CommonMethod() +3;
}
}