Back to list
Views:   7.7K
Replies:  1
Archived

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?
Harshad Riswadkar, Feb 03, 2011
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.
Feb 26, 2011
Reply 1
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.

Rajesh Pillai, Mar 02, 2011


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2