Help, abstracting classes

S

Snedker

Hi folks,

I need some help to get this right:

On the data side I have two tables:

WishList
- WishListID
- UserID
- Description

Wish
- WishID (PK)
- WishListID (FK)
- ProductID (FK)
- Amount
- Bought

I've made two classes also named WishList and and Wish. I want for the
calls to the SQL-server (add, update, delete) to be abstracted to a
separate class, so I also have a class called Data.

Both classes of WishList and Wish have a Save() method (among others).
It's my thought to have a common Save() method for both classes, ie

Data data = new Data;
data.Save(..parameters..)

But the amount of parameters vary from WishList to Wish. So my
question is:

Can I have a common Save, or should I have a Data class for each of
the two classes (ie "WishData" and a "WishListData").

I hope I've explained myself well enough and very much look forward to
your responses.


Kind regards
Morten
 
A

Alberto Poblacion

Snedker said:
Data data = new Data;
data.Save(..parameters..)

But the amount of parameters vary from WishList to Wish. So my
question is:

Can I have a common Save, or should I have a Data class for each of
the two classes (ie "WishData" and a "WishListData").

You can have two overloads of the Save method with different parameters.
Or you can have a single Save(params object[] args) so that it accepts a
variable number of arguments. However, even though C# itself allows you to
have a single method for saving data into both tables, inside the method you
will need to branch into different code so that it saves the appropriate
data to the appropriate table. So in the end you will end up writing the
same code as if you had two methods, regardless of whether both of them were
in the same class or in different classes.
 
B

bob

Hi,
You may want to consider using a typed dataset and having a
DataAdapter fill / update the dataset in the data class.
This probably comes closest to your 'one stop shop' for data update /
retrieval.
regards
Bob
 

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