Interface Delimma

J

James Curran

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
 
A

AlexS

Possibly you can use something like AddField - see how it is done for
parameters in SqlCommand with SqlParametersCollection

HTH
Alex
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top