Difference between data access level and database abstraction level and database class refactoring

Possible duplicate:
What is the difference between a data abstraction layer and an Acesh Layer data layer?

I just read this article on nettuts. I was a little embarrassed. What is the difference between the level of data access and the level of database abstraction ?

Also, should I create my own custom classes for this, or is it better to use PDO?

I have a DatabaseOps class that performs all CRUD operations. Other classes (for example, User) inherit from it and use the methods of this class to perform CRUD actions. I have another class called Database that makes an open connection, closes the connection, receives an array, confirming the request, etc. Should I write them to a single class (Data Access / Abstraction Layer)? Which one is better?

+4
source share
2 answers

The data access layer usually takes the form of ORM. This allows you to map tables to objects. It provides a high level of abstraction, so you don't have to worry about raw sql. http://en.wikipedia.org/wiki/Data_access_layer

The data abstraction layer creates an api that makes independent access to the database. Do you use postgres, mysql, sqlite etc. This will allow you to query these databases without worrying about specifics. http://en.wikipedia.org/wiki/Database_abstraction_layer

If you are creating a platform that others can use, and they can choose their database backend, an abstraction layer is required, otherwise I would not worry about that.

Whenever I have questions about the structure of web projects, I always look at the popular MVC structures to see how they deal with these problems. CakePHP, CodeIgniter, Kohana, are great examples of creating extensible object-oriented frameworks. They are an indispensable resource when it comes to such issues.

+6
source

I am not an ideal programmer, but from what I saw / learned, it is important to have a separation of duties. That is why layers of abstraction are taught so much.

This is how I will look at it. Ask these questions ...

  • Will you always use only one type of database?
  • If you plan to use more than one type of database (or just plan to make a project that is easier to set up ... which I recommend), all database commands (including CRUD) have the same syntax for access, delete, insert ...? (Most likely they do not)

In my opinion, if I had to answer these questions, I would put two classes together. That way, if your database ever changes, you can easily add a new level of abstraction that will be called, which has access commands and CRUD, instead of creating two different classes.

PS Great question! +1

+2
source

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


All Articles