3-Tier architecture is one of the most popular approaches in software development.
Tier Vs Layer
Tier indicates a physical separation of components.
Here separate assemblies/services are made to represent each component.
Layer indicates a logical separation of components with the help of namespaces and classes
Components of 3-Layer Architecture
- Presentation Tier: in simple terms, the UI with which the end user actually interacts.
- Data Tier: Where actual data is stored.
- Business Tier: It acts a bridge between Data Tier and the Presentation Tier. It collects raw data from the Presentation Tier, checks for validations, converts them to a standard format and finally sends them to the Data Tier. Similarly it collects data from the Data Tier, purifies it and sends it to the Presentation Tier for display.
- Business Objects: Its nothing but a class representation of actual data.
How it Looks
Code Walkthrough
What we are developing.
We are developing a customer screen which supports 2 operations:
- Add New Customer
- List All Customers.
Now customers may be of the types
Gold, Silver or Normal which represents Id as 1, 2 and 3 respectively.
Note: In the database CustomerTypeId will be stored but in the grid the descriptive text will be shown.
Step 1: Create Business Objects required - we need 2 things,
one representing the customer type and anotehr representing the customer itself.
public class ClsCustomerType
{
public ClsCustomerType(int id)
{
this.Id = id;
switch(Id)
{
case 0:
this.Name = "--Select--";
break;
case 1:
this.Name = "Gold";
break;
case 2:
this.Name = "Silver";
break;
case 3:
this.Name = "Normal";
break;
}
}
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
}
public class ClsCustomer
{
public string CustomerCode
{
get;
set;
}
public string CustomerName
{
get;
set;
}
public ClsCustomerType CustomerType
{
get;
set;
}
}
}
Step 2: Create Business Access Layer
public class ClsCustomerBAL
{
public List<ClsCustomerType> LoadCustomerTypes()
{
return new List<ClsCustomerType>()
{
new ClsCustomerType(0),new ClsCustomerType(1),new ClsCustomerType(2),new ClsCustomerType(3)
};
}
public IEnumerable<ClsCustomer> LoadCustomers()
{
DataTable dtCustomer=new ClsCustomerDAL().LoadCustomers();
}
public void SaveRecord(ClsCustomer objCustomer)
{
new ClsCustomerDAL().SaveRecord(objCustomer);
}
public ValidationResult ValidateCustomerCode(string strPriCustomerCode)
{
if(strPriCustomerCode.Trim() == string.Empty)
{
return ValidationResult.Empty;
}
else if(strPriCustomerCode.Trim().Length < 5)
{
return ValidationResult.InValid;
}
return ValidationResult.Valid;
}
}
Step 3: Next we need a Data Access Layer:
using System.Data;
using System.Data.SqlClient;
using Entities;
namespace DAL
{
public class ClsCustomerDAL
{
private const string ConnectionString = @"Data Source=SUKESH-PC\S2;Initial Catalog=3LayerApp;Persist
Security Info=True;User ID=sa;Password=aa";
public DataTable LoadCustomers()
{
//Load Data From Database
}
public void SaveRecord(ClsCustomer objCustomer)
{
//Save Data Into Database
}
}
}
Step 4: That's it; now the only thing remaining is creation of the UI:
In the UI the code behind we will just call the functions created on BAL, there will not be any database logic, and neither wll there be validation logic.
Hope this explanation was enough to understand, how to create a simple 3-Layer application using ASP.Net also I hope you enjoyed reading this article.
Please download the source code to better understand the functionality.
Make sure to put some good comments.

Aryan ThakurPosted Aug 26, 2014, 3:09 AM
Very Good
emmanuel constantPosted Nov 20, 2013, 3:02 PM
did you use VS 2010 for this?
nilesh mondePosted Apr 4, 2013, 7:00 AM
the Zip file u provided in my vs 2010 ultimate it is not open ? what can i do .. thanx in advance
nilesh mondePosted Mar 23, 2013, 12:05 AM
how to laod data from databse and how to save where is code?
bhargav pandyaPosted Dec 11, 2012, 12:36 PM
because if all remaining at client end makes it again client server architecture.. only thing is references are made by different files... also according to one article by microsoft it is very important that only one DAL is running in the network at server end. so how do we deply this solution on three different physical systems..
bhargav pandyaPosted Dec 11, 2012, 12:33 PM
Helo.. I got this well.. But i still dont understand how we deploy all layers on different physical systems.. because since we are referencing each solution on other.. it is important that all BAL dll are available at client end. and DAL dll are available at BAL.. so can you please detail this out about deploying this architecture on different physical systems..
bhargav pandyaPosted Dec 11, 2012, 12:33 PM
Helo.. I got this well.. But i still dont understand how we deploy all layers on different physical systems.. because since we are referencing each solution on other.. it is important that all BAL dll are available at client end. and DAL dll are available at BAL.. so can you please detail this out about deploying this architecture on different physical systems..
siva kumarPosted Oct 11, 2012, 4:58 AM
Better but complex
siva kumarPosted Oct 11, 2012, 4:57 AM
Better but complex
sayyad hasanPosted Oct 3, 2012, 6:47 AM
good job nicely described
Shivanand ArurPosted Sep 26, 2012, 2:43 PM
Good one Sukesh... Keep it up dude... :)
Sukesh MarlaPosted Sep 25, 2012, 11:13 AM
Thanks meghana,My Pleasure
meghana achariPosted Sep 25, 2012, 7:39 AM
Ya good one helped me a lot
meghana achariPosted Sep 25, 2012, 7:39 AM
Ya good one helped me a lot
meghana achariPosted Sep 25, 2012, 7:39 AM
Ya good one helped me a lot
Sukesh MarlaPosted Sep 7, 2012, 4:53 AM
sure dear, u will get, Thanks :)
minuPosted Sep 7, 2012, 3:59 AM
really gud article....thanxs...n luking fwd 2 hve many more....:)
Sukesh MarlaPosted Sep 6, 2012, 12:32 PM
yes, i prefer to that,Main advantage is It makes UI(aspx part) less cluttered, and even code management is easy, if i want to comment any event, its easy.
Ram Sagar MouryaPosted Sep 6, 2012, 8:28 AM
Sukesh ,good article , Is there any advantage of assigning the click event method in the code behind for button instead of mentioning them in .aspx page.
Anubhav sahuPosted Sep 6, 2012, 6:36 AM
great job .....
sudheer kumarPosted Sep 5, 2012, 12:37 AM
t5t45y54y56yyyy5yy
Sukesh MarlaPosted Aug 19, 2012, 8:16 AM
IN the same way, Crea Form for login, On Login_click pass values as username and password to Bal which will pass the values to DAL. DAl checks for validity and return the value to BAL and then to UI. Understnad 3-Tier is a architecture which tells us how to place the things and how they talk with each other.
KRayudu VPosted Aug 19, 2012, 8:02 AM
Nice Article.But,How to create a login page in asp.net C# by usig 3tier aechitecture
Mahesh ChandPosted Aug 18, 2012, 9:31 PM
EDITORIAL FEEDBACK: Keywords should be limited to 5 only.
Sukesh MarlaPosted Aug 17, 2012, 10:39 AM
Anil download the sample source code attached with the article.
anil babuPosted Aug 17, 2012, 7:07 AM
Tell me the complete example on 3 tier Architecture? How to Perform All DML operations in database Entitydatamodel(OR)any thing help me