Pergunta

I know this may be a duplicate question. But i never found a correct explanation that a beginner like me can understand.

My question is "What all things we can do inside Business Logic Layer". I have done 3 tier architecture projects. But I used BLL only to pass values between UI and Data Layer.

But whenever i attend an interview they asks me what all things you do inside BLL.
Please help me to understand the correct use of BLL.
Please provide little bit of sample code if you can.

Foi útil?

Solução

This question may get deleted because it is not in the format that stackoverflow likes.

BLL handles the business logic such as how to do a specific formula or execute a workflow. It will typically contain rules that a company wishes to implement.

The data layer typically just gets data from the database, file or some other data source and doesnt do any further modification to it. It is usually the business layer that loads the data into some kind of business relevant class/object. The BLL may also modify the data from data layer before it passes it to the UI layer. The UI layer only does simple validations and renders the data it gets from the BLL

For eg.

in the datalayer

you could have a function

public DataSet GetAllAccounts()
{
 DataSet ds;
 //Some sql code to read out the sql data using datareader and dataadapter;
 return ds;
}

and in the business layer you could have

public List<Account> GetAllAccounts()
{
 DataSet ds = DataLayerClass.GetAllAccounts();
 return (from Tab1 in ds.Tables[0] select new Account(){AcctNum =Tab1.AcctNum, Name =Tab1.Name}).ToList();
}

As you can see, Account is a business specific object whereas DataSet is something that is relating to the db and doesnt care about business or any business rules.

Outras dicas

You can safely switch from one database to other if all your business logic, I mean data processing, is done seperately.

Also you can support multiple databases (SQL Server, MySql, Access, Text files) using the same code.

first you should know that why we separate our object to two separate layer of data and business whereas in object oriented data and action are in the same class the reason is here when we are producing enterprise app commonly our data changes is rare but our business are about to changing so this pattern help us to change the specific part,

If you understand the one of main reason of using 3 layer pattern now to answer your question all of logic which are in your real business could be over there with the same name, for example in financial projects RegisterVoucher can be a method to register a voucher note and all validation you should check before it register.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top