Ashish
Ashish

Reputation: 391

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?

Upvotes: 6

Views: 2155

Answers (3)

Paul
Paul

Reputation: 457

You can use following design:

DAL:

namespace DAL.Repository
{
    public class UsersRepository
    {
        public static IList GetUser(string UserId)
        { 
            using(MyDBEntities context=new MyDBEntities())
            {
               // it calls SP in DB thru EF to fetch data
               //here you can also context.user to fetch data instead of SP
                return context.GetUser(UserId).ToList();

            }
        }
    }
}
BLL

namespace BLL
{
   public class User
    {
       public static IList GetUser(string UserId)
       {
           return DAL.Repository.UserRepository.GetUser(UserId);
       }
    }
}
PL

  ddlUser.DataTextField = "UserName";
  ddlUser.DataValueField = "UserId";
  ddlUser.DataSource= BLL.User.GetUser(string.Empty);
  ddlUser.DataBind()

Note: while sending data from BL to PL converting DB Entity to Business entity is required if you want to loop thu data in PL.

Upvotes: 0

Eric J.
Eric J.

Reputation: 150108

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;
    }
}

Upvotes: 2

Luke Schafer
Luke Schafer

Reputation: 9265

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.

Upvotes: 4

Related Questions