Should DB layer elements be static or instances?

I have seen projects in which classes at the database level have only static functions in them and other projects where these classes must be created to access member functions.

Which is better and why?

+3
source share
6 answers

I like that one object is tied to one record in the database, i.e. object must be created. This is your main ActiveRecord template . In my experience, the approach with one object to one row creates a much more flexible and competent representation in the code. In addition, I like to treat objects as records and a class as a table. For example, to change the name of an entry, follow these steps:

objPerson = new Person(id)

objPerson.name = "George"

objPerson.save()

, ,

aryPeople = Person::getPeopleFromState("LA")

Active Record. , , , . - DataMapper.

ORM . , , , , .

+2

. , . , , .

, - :

DbController acrhive = new DbController("dev");
DbController prod = new DbController("prod");

.

, . , .

0

lomaxx, .

, , DAL. , DAL, 1, .

0

, , , " "...

sql, , , , .

, , .

, , , , ID (. @barret-conrad), , , , . , , , - DB Helper, DID , .

0

" ". , , . -, , , . ASP.Net , , , , , -.

0

, . ORM ( ) . ORM - , nhibernate, LINQ to SQL, Entity Framework . ORM - , , . , , , , .

, , Microsoft, , , . , SQL .

, ORM.

-2

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


All Articles