OO Design vs Database Design

Suppose I am developing an application for a product distributor in C #.

A distributor performs the following 3 types of transactions:

(1) Indent

(2) Sell

(3) Stock

I design my classes as follows:

public abstract class Transaction
{
}

public class Indent : Transaction
{
}

public class Sell : Transaction
{
}    

public class Stock : Transaction
{
}

Now, if I want to save these three types of information in three separate tables, then how do I create my DA level?

Should I create separate DA classes such as

(1) IndentDA
(2) SellDA
(3) StockDA

or one class TransactionDAand perform CRUD operations by checking their types with operators as/is?

Or what else can I do? Any suggestions?

+5
source share
7 answers

-, TransactionDA CRUD, / , .

, DAL, , , , , .

- Singleton

: Long Live

, , .

+5

. (, , , ) , . . , ( "" ) , . , .

, , , () , "" .

( ) , :

create table Employee (
  eid        int primary key,
  first_name text,
  last_name  text not null
)

create table Salaried (
  eid             int primary key,
  annualSalaryUSD money not null
)

create table Hourly (
  eid             int primary key,
  hourlyRateUSD   money not null
)  
+3

ORM, NHibernate, , .

+3

, , DA.

, , TransactionDA . , , , - , .

TransactionDA, .

+2

You can use dependency injection, create a DA class for each, and ensure that they all implement the same ITransactionDA interface with your CRUD transactions.

public interface ITransactionDA
{
  void Read();
  void Update();
...
}

public class StockDA : ITransactionDA
{
  //implement interface methods
}

Stock stock = new Stock(new StockDA());
+2
source

I will do something like this

public abstract class DistributerTransaction
{
    DistributerDA dataaccess;
}
public class Indent : DistributerTransaction
{
}
public class Sell : DistributerTransaction
{
}
public class Stock : DistributerTransaction
{
}

public abstract class DistributerDA
{
   /*Read();
     Update();*/
}
public class IndentDA : DistributerDA
{
}
public class SellDA : DistributerDA
{
}
public class StockDA : DistributerDA
{
}
0
source

All Articles