Solved

N-Tier Architecture in ASP.NET

Posted on 2013-01-10
3
460 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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now