Thursday, March 27, 2008

Modularizing the Data-Access Layer

I've been giving it some thought, and I think the Data-Access Layer(DAL) should refer to more than accessing data within databases. Data can come in many other formats such as XML, CSV, and SOAP(as a client only). So how do we change the DAL to incorporate different data types?

1. We set up a DAL interface object, insuring each type of data has a common set of operations. (Read, Write, Insert, Update, Delete).

2. We implement each type of DA as a Data-Access Provider (DAP). Most languages provide utilities for accessing different types of data. You can leverage those utilities within your DAPs.

3. Each DAP communicates with the Business Logic (BL) with Entities. For example, I need to retrieve data via SOAP and insert it into the database. The BL asks the SOAP DAP for a list of Entities. The BL then processes and filters the Entities. Finally, it asks the database DAP to insert the processed Entities into the database.

Resulting Structure


Standardizing the way we access and move data has many advantages. It simplifies the way we structure our code and project. It allows for optimal code reuse. It's modular, meaning you can add new DAPs as the need arises. Finally, configuration can allow you to change DAPs without re-compiling code.

No comments: