What is the purpose of a Data Access Layer?

Bryan Roth picture Bryan Roth · Sep 12, 2008 · Viewed 37.4k times · Source

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?

Answer

swilliams picture swilliams · Sep 12, 2008

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.