Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Access Layer and Business Objects

Not sure if I have the correct terminology, but I am a little confused on how to set up my 3-tier system.

Lets say I have a table of Users in my DB.

In my DAL, I have a UserDB class that calls stored procs into he DB to insert, update, delete. I also have a UserDetails class that is used in UserDB to return and pass in objects.

So now I am not sure how to use this in my Business Logic Layer. Do I need another BLL object class for users? If so, would this not be redundant? Or do I just use the UserDetails class throughout my BLL?

like image 514
Ashish Avatar asked Aug 10 '09 02:08

Ashish


People also ask

What is the difference between Data Access Layer and business logic layer?

The data layer manages the physical storage and retrieval of data. The business layer maintains business rules and logic. The presentation layer houses the user interface and related presentation code.

What is business access layer?

It acts as an interface between the user and the application. Business Logic Layer: It acts as an intermediate between the Presentation and the Data Access Layer. Data Access Layer: The layer at which the data is managed.

What is the purpose of a Data Access Layer?

Data-Access Layer (DAL) Data-Access Layer is a layer in an application that provides easy and simplified access to data stored in persistent storage, such as an entity-relational database or any database for that matter. It is layer that exists between the Business Logic Layer (BLL) and the storage layer.


2 Answers

Look up a concept called 'Domain Driven Design' - the biggest thing there is using what's called a repository pattern (such as your UserDB class) as an adapter to the database, as well as a factory. Your business objects, or domain objects, then incorporate business logic into themselves and can handle interactions with other business objects.

What technology are you using? Something like ActiveRecord can probably help you a lot.

like image 120
Luke Schafer Avatar answered Oct 18 '22 14:10

Luke Schafer


You typically would enforce Business Rules in your BLL. For example, you might allow regular call center employees to offer a 10% discount on new service but allow a manager to offer a 20% discount. You would have a business rule in your BLL that goes something like:

// Pseodocode
double Discount
{
    set
    {
        if (value > 10% AND Employee Is Not Manager) then throw Exception
        if (value > 20%) then throw Exception
        discount = value;
    }
}
like image 40
Eric J. Avatar answered Oct 18 '22 16:10

Eric J.