Home  /  Questions  /  Question



256   99.6
Feb 03, 2011


Issue with direct dependency of code on the Database

Hi,

I am working on a Web Application in which an automated email is fired when a user logs in to the web site. Currently the code that validates login, passes the ActivityId to the relevant method. The ActivityId is then used in the query to get the appropriate email from table (the table has ActivityId column and value).

Here the issue is the direct dependency of the code on the Database.  In case if appropriate record is missing from DB, the relevant email will not be fired. I want to remove this dependency by introducing some sort of a Design Pattern.

Can anyone please provide some guideline on this?
 1 comment
 
Without more details, I can only give general advice about what I would look at. Firstly you might want to try to use a "factory" pattern to return the correct email object. Or you might like to look at a "proxy" object. --- Trevor Lane  Feb 26, 2011



1,364   100.0
Mar 02, 2011
One of the basic design is to layer your applications into tiers (atleast minimum 3 tiers).  There may be more layers, but that depends on the nature of the app being designed.

- Presentation Layer (UI)
- Service Layer
- Data Layer


But in any case the "Presentation Layer" never directly talks to the "DB" Layer.  It is the responsibility of the service layer to talk to the DB.

Also, to abstract further, you may have the Repository Layer between Service and Data Layer as follows..

- Presentation Layer (UI)
- Service Layer
- Repository Layer
- Data Layer

Hope this helps.