Hi James,
if you are trying to design in a layer of abstraction into your system,
you might need to use one more layer to get a generic interface like the one
you outlined below. This could possibly follow the Data Mapper Design
Pattern architecture
i.e.
interface IDBMapper
{
insert();
update();
delete();
}
class Person
{
public Person()
{
}
public int Id
{
//returns the id of the person record in the database
}
public string Name
{
//return the name of the person
}
public int Age
{
//return the age of the person
}
}
//object that lives inbetween the higher level object and the database
class PersonMapper : IDBMapper
{
private Person m_p;
public PersonMapper(Person p)
{
m_p = p;
}
public void Insert()
{
//insert into tblPerson new entry with m_p.Name, m_p.Age etc
}
public void Update()
{
//update tblPerson where id==m_p.Id, using
//m_p.Name, m_p.Age etc
}
public void Delete()
{
//delete from tblPerson where id == m_p.Id
}
}
In doing this you can now hold reference to IDBMapper without having to
worry what is the underlying concrete type and they all have the same
interface to the high level controller. You would have to have one data
mapper per object that maps to tables in your DB.
Not sure if this is the kind of thing you are looking at or not in your
design.
Mark
"James Curran" wrote:
We are in the process of design a new of classes which are essenially
E/R object for our db tables. Each would have the standard CRUD operations.
We plan to have a common interface that they all implement, basically:
interface MyInterface
{
Read(int id);
Update(int id);
Delete(int id);
}
The problem is.... How do we put "Create" into the interface, since
besides the key field, it would need as parameters, each field for the
object, which would be different for each class. Using "params object[]
args" was considered, but we'd rather have the compile-time type checking.
Any ideas?
--
--
Truth,
James Curran
[erstwhile VC++ MVP]
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com