After receiving a lot of comments and email on my
ADO.NET post, It's obvious I didn't explain myself very well. The real question is how do we maintain schema abstraction.
"By this I mean that we use methods like GetStudy(int StudyID) in a class called DataDB instead of a method called SelectByID(int id) in a class called TblStudiesBase." We want to have most, if not all of these methods in a single class. That way the developer only has to instantiate a single object to interact with the data. They need to know virtually nothing about the schema. The problem comes in when you add new developers to the team. They say "Hey there's no FindStudy(int StudyID)" so they add it. But the same code already exisits as GetStudy(int StudyID). While I agree that as a Team lead it's my job to oversee and review the new developers work, it's time consuming reviewing everthing the new developer has done. I've been thinking of doing something like this to keep things a bit more organized:
using System;
using System.Data.SqlClient;
namespace MyCompany.MyApplication.Data
{
public abstract class DAL
{
protected SqlConnection m_conn;
protected DAL(SqlConnection conn)
{
m_conn = conn;
}
public abstract object Get(int id);
public abstract void Set(int id, object data);
public abstract void Remove(int id);
}
public class StudiesDAL : DAL
{
public StudiesDAL(SqlConnection conn): base(conn){}
public override object Get(int id)
{
// TODO: do the get on studies
return null;
}
public override void Set(int id, object data)
{
// TODO: do the set on studies
}
public override void Remove(int id)
{
// TODO: do the remove on studies
}
}
public class MeasurementsDAL : DAL
{
public MeasurementsDAL(SqlConnection conn): base(conn){}
public override object Get(int id)
{
// TODO: do the get on measurements
return null;
}
public override void Set(int id, object data)
{
// TODO: do the set on measurements
}
public override void Remove(int id)
{
// TODO: do the remove on measurements
}
}
public class DataDB
{
protected SqlConnection m_conn;
public StudiesDAL Studies = null;
public MeasurementsDAL Measurements = null;
public DataDB()
{
m_conn = new SqlConnection("SOME_CONNECTION_STRING");
Studies = new StudiesDAL(m_conn);
Measurements = new MeasurementsDAL(m_conn);
}
}
}
Comments?
5d62aacf-4917-41ac-9030-6418d0cd8eb4|0|.0