There is a need to reorganize a large level of data access

I have a data access layer that abstracts the rest of the application from storage technology. Now the implementation is an SQL server, but this may change. In any case, I believe that this main data access class becomes more and more as my tables grow (about 40 tables). The interface to this level of data access is any question you might want to get on

 public interface IOrderRepository
 {
       Customer[] GetCustomerForOrder(int orderID);
       Order[] GetCustomerOrders(int customerID);
       Product[] GetProductList(int orderID);
       Order[] GetallCustomersOrders(int customerID);
       etc . . .
 }

the implementation behind this is the basic SQL stored procs that run the appropriate queries and return results in typed collections

it will grow and grow. It is quite convenient to maintain, since there is no real gap in shared responsibility, but the class now exceeds 2,000 lines of code.

therefore, the question is, of course, what is the size of the class (and there is no real conceptual connection), if it is broken, and if so, what dimension or level of abstraction.

+3
source share
4 answers

Absolutely refactoring. 2000 lines are huge.

I would start by breaking down the return type. Thus, you will receive one class for access to Products, one for Orders, one for Customers, etc.

For each of the classes, the set of selected columns should probably be the same so that it can be reorganized into a single variable / method as extracting SQL values ​​into objects.

Also, the actual call to the stored procedure, including logging and exception handling, can and should go into a separate class.

, . , :

  • SQL- ( 40 )

- -

+2

, - . , . , , - , , / .

+1

... , - - ; - ( ). , DB, .

, , , -. , .

. , , - , -, , . SQL Server ( ). .

+1

DAO, . , .

0

Source: https://habr.com/ru/post/1726508/


All Articles