Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

N-Tier Architecture in ASP.NET

Posted on 2013-01-10
3
Medium Priority
?
501 Views
Last Modified: 2013-01-12
In this section, "Creating Business Access Layer (BAL):   (RecordBAL.cs)", I do understand the code. What I don't fully understand is is that all there is for Business layer? I don't understand how it benefits by just return data?

 "//and return the result to the caller of the method.
            return rdAL.RetrieveRecords(); " 

" Its responsibility is to validate the business rules of the component"  <<< If you have a sample, could you help me out what this mean?

http://www.mindstick.com/Articles/d36ceb0f-018c-4979-b2f5-a4a1e616cb5b/?N-Tier%20Architecture%20in%20ASP.NET
0
Comment
Question by:VBdotnet2005
3 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 38766037
0
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 38766518
Well, many times the business layer simply returns the data "as-is" from the data layer to the UI. But data in the database is not always stored exactly the same way that it must be shown in the UI, so therefore many other times you'll need to make some transformations in the data.

In the sample page you provided I miss one more layer, that I used a long time ago and I consider invaluable: the repository. In my projects, the UI layer doesn't know the database at all; in fact, in the UI I never use database objects like datatables, datasets, etc. For me, it's much clear to declare a repository layer where I create classes for all my entities. So when I need to retrieve, for example, a list of "persons" from my database, in the UI I don't get a datatable or dataset, but a list of Person objects. The Person class is declared in the Repository layer.

Now, let's back to the business layer. The business layer will be useful to you in 2 ways. First, when retrieving data from the database. In most cases, the data in the database is not stored exactly the same way that you need to show it on the UI. For example, my Person class does't need to be an exact copy field-to-field of what is stored in the database. So often you'll need to make some transformations to the data collected from the database. Following my example, the business layer would get a list of person records from the database and will fill a list of Person objects with those records, making some transformations in the data to fill right the Person objects.  When it's done, the list of Person objects will be sent to the UI.

The second way the business layer will be useful is when providing data to the database (new records, updates, deletions, etc). The BL will be the responsible to store your business logic. For example, you'll need to do some validations to the data provided when creating a new record. more over than the simple validations that you'll do in your UI (empty fields, etc). Imagine that you have this business logic: "It's not possible to create a person when his phone number already exists in the database". Well, in your UI you'll probably check that the phone number is not empty when creating the person, but you have no way to check directly from the UI if the phone number already exists. So in the UI you'll do some basic validations (mainly those format-related) and in the BL you'll do your business-specific validations. If the phone number exists in the database, the BL must return that condition to the UI in order to inform the user.

Wow... I hope this will be useful to you. It's not easy to me to express in English, as it's not my native language. I hope you understand what I wanted to say.
0
 

Author Comment

by:VBdotnet2005
ID: 38770496
I truly appreciate your help on taking time to write above. Wow, that helps alot.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question