Part 1:Why Using Data Access Layer

I know it's too late to talk in this topic, but some times we are using a certain technology or methodology without knowing why we are using it :), we found others using it and we just follow them.
Today I am going to tell you why we are using Data Access Layer (DAL) using an simple application to simplify the idea.

Before we start what is the Data Access Layer:

"A Data Access Layer (DAL) 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." Wikipedia

In more simple words, it's an object mapping for your relational database. It means that when you are using DAL you will not access the database directly from code but you will access the DAL which will access the database.

The Example:

Suppose you were asked to design and develop a web application (using any technology) this application will be deployed on 2 servers (Application server & Database Server), the database server will be MS Access or MySQl in phase 1 , then it will be upgraded to MS Sql Server or Oracle according to the increase of data in phase 2.

If you are going to use traditional data access by writing queries inside the code (inline queries) and execute it from your application you will face the following problems:

-Rewriting of common queries ... example if you are going to select from table users with different filters in different files you will rewrite the statement "Select * from users where ...." many and many times

- No Strong Types .. which means that database tables, columns or relations are not presented in your code, so you have to execute queries using text statements with the ability to make mistakes without any compilation errors (you will see errors just in executions) specially if you have change in the database structure or even one column name (you have to go through all the application)

- One database engine support... because all queries are directly written inside the code, so if you decided to change the database engine you have to rewrite many SQL queries because SQL syntax is not standard in all database engines.

-Security Obstacles
.. in our example if the database server does not allow opening ports except HTTP port (port 80), your application will not be able to execute queries or even to connect to the database, but by using DAL you can convert your DAL to a webservice and deploy it on your Database server to consumed from your application. as shown:
I've tried to write in few points why I've used DAL in my last 5 years, in the next part I am going to write about how to choose a suitable DAL with a full comparison between available DAL frameworks and generators.

You can leave a response, or trackback from your own site.

0 Response to "Part 1:Why Using Data Access Layer"