Chandra sekhar
Chandra sekhar

Reputation: 167

Purpose of BAL in 3 tier architecture

I am a newbie for 3 tier architecture as it consists of UI,BAL and DAL layers.So i am writing all the database code in DAL and i have declaring the variables in BAL and i have calling the methods into the UI,but is this is the correct way to code??What is my BAL is doing then?what is the main purpose of business layer?Can anyone explain me,Thanks.

 //In my BAL



public class ProfileMasterBLL
{
    public int UserId { get; set; }
    public string FormFiledBy { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

}

//In my UI

 ProfileMasterBLL pmBLL = new ProfileMasterBLL();
        pmBLL.FirstName = TextBox1.Text;
        pmBLL.LastName = TextBox2.Text;



//In my DAL 

method for insert()

then how can i call ProfileMasterBLL.insert() ?? as i have written in DAL.

Upvotes: 0

Views: 4962

Answers (3)

JonH
JonH

Reputation: 33153

Business Layer is used as the middle man between your UI and the DAL. It is used for any or all business logic that your application will encompass. For example, in an accounting application you may want to perform some calculations and checks on the data before you send it off to the database layer, you would perform this in the business layer.

Your UI could do something like so:

//establish person object
//pass in some salary with it to BL
BL.CalcPay(somePerson, someSalary);

Then in your BL:

//inside of BL
//if its a CEO they are lucky, they get paid twice as much
 decimal toGive = someSalary;
if(somePerson.IsCEO)
 toGive = toGive * 2; //CEO gets paid more :(

//now call DAL
DAL.CalcPay(somePerson, toGive)

Then in your DAL:

//inside of DAL
//perform some update by calling for instance a sproc
using(SQL....)
{
}

Not the best of examples but it should get the point across, there are many times where your BL doesn't do anything but hand off a method call to the DAL. Just because it is the BL doesn't mean it has to have some sort of check associated with it. So you may end up doing something like this:

//inside UI
string s = BL.GetSomeString();

//inside BL
return DAL.GetSomeSomeString();

//inside DAL
return someString;

Upvotes: 1

rs_atl
rs_atl

Reputation: 8985

The business layer exists to provide a place to put your business logic. Data access logic should do nothing but create, retrieve, update, and delete (CRUD) operations against your database. The presentation layer should have nothing but the logic that determines how your user interacts with the system.

For example, if you click "add user" in your UI, this could call an BAL.AddUser() method in your business layer that would then call multiple data layer methods, such as DAL.AddUser() to insert the User, then DAL.AddUserToGroup() to put the new user in a default group.

Upvotes: 0

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

The role of Business Layer is to execute business rule, for example validation of your entities, execution of business rules on the entities, execution of business function on entities.

often you have two choices.

Implement business logic in stored procedures

or

Implement business logic in the business layers

Upvotes: 0

Related Questions