views:

48

answers:

3

Hi,

I am using asp.net and c#.

I have a some classes. Some of the classes are having same methods insert, update and delete.

Each insert will insert different data to different table. (same for update and delete). What type of pattern can be applied for this kind of class.

please suggest.

A: 

Uhm... Generics?

Otherwise this sounds like the Template Method pattern.

Mark Seemann
+5  A: 

Patterns are things you should identify in your code from usage. Choosing a design pattern and then applying it, is perhaps a classic mistake.

Use a pattern, where a pattern is required.

Mitch Wheat
A: 

While I agree wholeheartedly with Mitch Wheat, based on your description I do believe you're already using a pattern, without being aware of it completely.

Based on you description, I believe you are talking about the Table Gateway pattern. Each class represents access to a specific table, so you can perform your CRUD operations on a class. This offers a very tight binding of your model to your database logic, which can sometimes be useful (and more often than not can become very restrictive).

BTW: I am making the assumption here that when you say "each insert will insert different data to different table (same for update and delete)", you actually meant "each class".

kander