Click here to Skip to main content
15,867,686 members
Articles / Web Development / ASP.NET

Multi-tier Enterprise Application Architecture

Rate me:
Please Sign up or sign in to vote.
3.21/5 (30 votes)
19 Jan 2009CPOL5 min read 86.4K   92   23
Multi-tier Enterprise Application Architecture

Introduction

Multitier architecture, often referred to as ‘N’-tier architecture, is a software system that is segregated into separate sections referred to as tiers, or layers. By default, the ‘N’ value is presumed to be three.

The first and the foremost question for a person after reading the above lines, "Why do I need these layers, what purpose do they solve?".

Software applications are constructed with this methodology for many a reasons. Foremost is the ability to provide the optimal amount of “scalability” to the system and allow any of the tiers to be upgraded, replaced, or interchanged independently.

At some point in a software system, there is the inevitable “Change”. This change can come in the form of a functionality change, a functionality enhancement, a completely new module, or even a hardware infrastructure enhancement and so on. In any case, changes can occur during the initial development or after the first version is complete. Thus it becomes mandatory to have the architecture of the system designed from the beginning as “multitiered”. This will help us to minimize the impact on the system when implementing any change to any layer.

As a result of having the source code organized into multiple tiers, debugging and maintaining your application as a whole will be easier. The organization will allow for you as a developer (or any other developers you might be working with) to easily locate specific sections where an exception is occurring or where a change needs to be implemented.

If the system does not implement a well-structured architecture, your application will be prone to defects and bugs; this will also make any type of upgrades or enhancements difficult and time-consuming to execute. The system will not be very scalable, which will result in a poor application.

A typical multi-tiered application consists of:

  • Presentation Layer (this is simply our website application)
  • Business Logic Layer (the Brain of our application)
  • Data Access Layer (the Data Processing section of our application)

Now comes a quick question. “Do all these layers exist on only one machine?” Yes and No! Confused? Don’t be. This is how it works!

In a multitier architecture, all the layers are present like the above three. It all depends upon the fact if the layers are all on one machine itself or distributed over several machines across the network.

Let us say, we need to get the web-server running, store our data in the database and have the web application also running on the same server (low budget project :)). Then this would also be called as a 3-tier application.

Detailed Description

Consider the following image below as a reference for the upcoming description:

New_Picture.png

Overall Solution Structure

New_Picture__1_.png

Presentation Layer

This is the presentation logic layer. This is what the users will view. This includes simple control and user input validation. This application is also known as a thin client. It is similar to our web application. It has a reference of our business layer. This layer has no knowledge about the system working, database or any information.

Example

The following page is in the code behind file of an aspx page. There is a reference to the Business Layer only in the following sentence.

C#
using XOR.Development.Ecommerce.XORBusinessObjects;
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using XOR.Development.Ecommerce.XORBusinessObjects;
namespace XOR.Development.Ecommerce.WebApp
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {          
        }         
        
        protected void btnUserRegister_Click(object sender, EventArgs e)
        {
        }
    }
}

Business Logic Layer

This is the ‘brain’ of our entire application. It provides the business processes logic and the data access. The business logic layer of the architecture will act as a bridge from the presentation to the data access so that the information can be processed in some cases and, in other cases, can simply be the conduit to ensure the smooth flow of information. This layer will have the most information about the activity and the processing that needs to take place. This layer will have heavy implementation of the business objects.

This layer does not know any information to access data. In fact, it has no knowledge how to retrieve information. It just gives the requirement to the Data Access Layer. This layer sets forth the business rules from the earlier gathered requirements. Look at the references in the below picture for a clear understanding.

Sample Business Layer Project in a Solution

New_Picture__2_.png

Example

The example below is the class file which accepts data from the presentation layer. This layer has references of Common Objects, Data Access Layer, Business Interface Libraries.

The application example here uses the ‘ProcessSelectProducts’ class file in the data access layer. It sends information to the file (ProcessSelectProducts) which gets the data from the database.

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using XOR.Development.Ecommerce.XORBusinessInterface;
using XOR.Development.Ecommerce.XORCommonObjects;
using Microsoft.ApplicationBlocks.Data;
using Microsoft.ApplicationBlocks.Data.Select;
namespace XOR.Development.Ecommerce.XORBusinessObjects
{
   public class ProcessGetProducts : IXORBusinessLogic
   {
       public ProcessGetProducts()
       {
       }
       private string _searchcriteria;
       public string SearchCriteria
       {
           get { return _searchcriteria; }
           set { _searchcriteria = value; }
       }
       private DataSet _resultset;
       public DataSet ResultSet
       {
           get { return _resultset; }
           set { _resultset = value; }
       }
       
       #region IXORBusinessLogic Members
       public void Invoke()
       {
           ProcessSelectProducts oProcessSelectProducts = new ProcessSelectProducts();
           ResultSet = oProcessSelectProducts.Get(SearchCriteria);
       }
       #endregion       
   }
}

Data Access Layer

This is the only layer in our application which knows how to interact with the database servers and retrieve the required information. It has no knowledge as to who is asking or whom is it giving the information to. All it knows is that it needs to give information back to the request object.

Data retrieval process will most likely be in the form of selecting, querying, inserting, updating, or deleting information to and from the database. Other processing includes utilizing Extensible Markup Language (XML) data but this will ultimately vary based upon your specific system and its business requirements.

Example

Consider the example below.
This class file in the data access layer is used to perform the ‘Select’ operation over
the database tables.

C#
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using XOR.Development.Ecommerce.XORCommonObjects;
namespace Microsoft.ApplicationBlocks.Data.Select
{
 public   class ProcessSelectProducts : XORDataAccessBase
    {
     public ProcessSelectProducts()
     {
         //TODO Constructor
         StoredProcedureName = XORStoredProcedures.Name.USP_SearchAllProducts.ToString();
     }
     public DataSet Get(string SearchCriteria)
     {
         DataSet ds;
         ProductSelectSearchDataParameters oProductSelectSearchDataParameters = 
			new ProductSelectSearchDataParameters(SearchCriteria);
         XORDataBaseHelper dbhelper = new XORDataBaseHelper( StoredProcedureName );
         ds = dbhelper.Run
		(ConnectionString,oProductSelectSearchDataParameters.Parameters);
         return ds;
     }
    }
    
    public class ProductSelectSearchDataParameters    
    {    
        private string _searchcriteria;
        
        private SqlParameter[] _parameters;
        public string SearchCriteria
        {
            get { return _searchcriteria; }
            set { _searchcriteria = value; }
        }
        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }
        public ProductSelectSearchDataParameters(string searchcriteria)        
        {        
            SearchCriteria = searchcriteria;            
            Build();        
        }
        
        private void Build()        
        {
            SqlParameter[] parameters =
		{ new SqlParameter("@UserSearchText", SearchCriteria) };            
            Parameters = parameters;        
        }
    }
}

Business/Common Objects

This is the layer which contains all the entities like credit card entity, address entity, end user entity and so on. Business/Common objects will also provide a direct mapping from the database tables you created earlier to the classes within your code. This does not necessarily imply that every common/business object will be a table within the database. Many will, but sometimes we will need a container of information that needs to be passed throughout the application. This will come in the form of a common object.

Sample Business/Common Objects

New_Picture__3_.png

Example

Consider the following example. This is a class file which describes the Order details.
It consists of all the requirements which consist of fields in the order processing.

C#
using System;
using System.Collections.Generic;
using System.Text;
namespace XOR.Development.Ecommerce.XORCommonObjects
{
 public   class OrderDetailsEntity
    {
     public OrderDetailsEntity()
     {
         //TODO Constructor
     }
        private int         _orderDetailsIdField;
        
        private int         _orderIdField;
        
        private int         _productIdField;
        
        private string      _productField;
        
        private int         _quantityField;
    
        
        public int OrderDetailsId
        {
            get
            {
                return _orderDetailsIdField;
            }
            set
            {
                _orderDetailsIdField = value;
            }
        }
        public int OrderId
        {
            get
            {
                return _orderIdField;
            }
            set
            {
                _orderIdField = value;
            }
        }
        public int ProductId
        {
            get
            {
                return _productIdField;
            }
            set
            {
                _productIdField = value;
            }
        }
        public string ProductField
        {
            get
            {
                return _productField;
            }
            set
            {
                _productField = value;
            }
        }
        public int Quantity
        {
            get
            {
                return _quantityField;
            }
            set
            {
                _quantityField = value;
            }
        }
    }
}

Conclusion

This concludes the multi-tier application architecture. I hope this article gives you insight into the advantages of splitting the application into multi layers. Good luck!!

History

  • 19th January, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Camelot Intergrated Solutions
United States United States
I am currently a DOT NET Software Consultant. Having said that, I am well versed in both front and backend. I got a very good amount of hands on experience in ASP.NET , T-SQL and a good amount of Database Administration, AJAX, JavaScript, SSIS and SSRS.

I am well versed in Enterprise Level Applications Architecture and Development.

I am even currently working as a Freelancer and build Content Management Systems in PHP and MYSQL.

Comments and Discussions

 
QuestionMulti tiering Do and Donts from a rebel Pin
devvvy8-May-15 15:46
devvvy8-May-15 15:46 
Multi tiering Do and Donts from a rebel[^]
dev

GeneralMy vote of 1 Pin
pramendra_dadhwal2-Sep-10 20:21
pramendra_dadhwal2-Sep-10 20:21 
GeneralMy vote of 1 Pin
hector garduno23-Aug-10 2:07
hector garduno23-Aug-10 2:07 
GeneralGood Article Pin
Vimalsoft(Pty) Ltd20-Aug-10 21:49
professionalVimalsoft(Pty) Ltd20-Aug-10 21:49 
GeneralMy vote of 5 Pin
Vimalsoft(Pty) Ltd20-Aug-10 21:48
professionalVimalsoft(Pty) Ltd20-Aug-10 21:48 
GeneralToo little detail for a newbie Pin
SiteBuilder11-Aug-10 20:08
professionalSiteBuilder11-Aug-10 20:08 
General[My vote of 2] Not bad - try to post AJAX article Pin
Pratik.Patel21-Jul-10 2:04
Pratik.Patel21-Jul-10 2:04 
GeneralHmmmmm Pin
fishyking4-Sep-09 20:42
fishyking4-Sep-09 20:42 
GeneralMy vote of 2 Pin
Josh Fischer1-May-09 8:05
Josh Fischer1-May-09 8:05 
Generaltoo little Pin
Donsw19-Feb-09 15:26
Donsw19-Feb-09 15:26 
GeneralMy vote of 1 Pin
Kjetil Klaussen27-Jan-09 8:48
Kjetil Klaussen27-Jan-09 8:48 
GeneralMy vote of 1 Pin
Maths20-Jan-09 7:39
Maths20-Jan-09 7:39 
RantThis might be the worse article I have ever seen on the code project! Pin
Member 313878520-Jan-09 6:28
Member 313878520-Jan-09 6:28 
GeneralRe: This might be the worse article I have ever seen on the code project! Pin
Venkata Ravula26-Jan-09 7:41
Venkata Ravula26-Jan-09 7:41 
GeneralRe: This might be the worse article I have ever seen on the code project! Pin
sandy Kumar12-Feb-09 23:08
sandy Kumar12-Feb-09 23:08 
GeneralRe: This might be the worse article I have ever seen on the code project! Pin
almog.ori5-Aug-10 8:44
almog.ori5-Aug-10 8:44 
GeneralMy vote of 2 Pin
tf12420-Jan-09 6:26
tf12420-Jan-09 6:26 
GeneralRe: My vote of 2 Pin
Ishitori20-Jan-09 23:10
Ishitori20-Jan-09 23:10 
QuestionWhy your code is so wordy? Pin
awisdom19-Jan-09 22:46
awisdom19-Jan-09 22:46 
AnswerRe: Why your code is so wordy? Pin
dl4gbe15-Aug-10 11:48
dl4gbe15-Aug-10 11:48 
GeneralHi ;) Pin
kaken2019-Jan-09 6:40
kaken2019-Jan-09 6:40 
QuestionGood article, but where is the source code? Pin
Ishitori19-Jan-09 5:36
Ishitori19-Jan-09 5:36 
GeneralGood Article, One comment Pin
mfahim19-Jan-09 4:51
mfahim19-Jan-09 4:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.