Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of a Data Access Layer? [closed]

I started a project a long time ago and created a Data Access Layer project in my solution but have never developed anything in it. What is the purpose of a data access layer? Are there any good sources that I could learn more about the Data Access Layer?

like image 919
Bryan Roth Avatar asked Sep 12 '08 20:09

Bryan Roth


People also ask

What is the purpose of a data access layer?

A data access layer (DAL) in computer software is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database. This acronym is prevalently used in Microsoft environments.

Is data access layer necessary?

A good data access layer is critical for most business applications, whether that layer resides on a middle-tier application server, a web server, or on the client.

What is data access layer in SQL?

A Data Access Layer (hence forward referred to as a 'DAL') for all intents and purposes is a user defined table function. A DAL is capable of accepting arguments to its parameters and in doing so is able to process data for the end user, whether or not any arguments have been passed to its varied parameters.

What is the meaning of access layer?

The access layer, which is the lowest level of the Cisco three tier network model, ensures that packets are delivered to end user devices. This layer is sometimes referred to as the desktop layer, because it focuses on connecting client nodes to the network.


2 Answers

In two words: Loose Coupling

To keep the code you use to pull data from your data store (database, flat files, web services, whatever) separate from business logic and presentation code. This way, if you have to change data stores, you don't end up rewriting the whole thing.

These days, various ORM frameworks are kind of blending the DAL with other layers. This typically makes development easier, but changing data stores can be painful. To be fair, changing data stores like that is pretty uncommon.

like image 153
swilliams Avatar answered Sep 24 '22 02:09

swilliams


There are two primary purposes of a Data Access Layer

  1. Abstract the actual database engine or other data store, such that your applications can switch from using say Oracle to using MS SQL server

  2. Abstract the logical data model such that your Business Layer is decoupled from this knowledge and is agnostic of it. Giving you the ability to modify the logical data model without impacting the business layer

Most answers here have provided the first reason. In my mind it is the second that is far more important. Essentially your business layer should not be aware of the logical data model that is in use. Today with ORMs and Linq #2 seems to go out the window and people tend to forget (or are not able to see the fine lines that do and should exist) about #2.

Essentially, to get a good understanding of the purpose and function of a Data Layer, you need to see things from the Business Layer's perspective, keeping in mind that the Business layer should be agnostic of the logical data model of your data store.

So each time the business layer need data for example, if should ask for the data it needs in a very simple logical data model agnostic way. So it would make a call into the Data Access Layer such as:

GetOrdersForCustomer(42)

And it gets back exactly the data it needs without being aware of what tables store this information of or relationship exists etc.

I've written an article on my blog that goes into more details.

The Purpose and function of a Data Access Layer

like image 43
Shiv Kumar Avatar answered Sep 20 '22 02:09

Shiv Kumar