3-Tier Architecture in .NET

Solution Explorer
Snapshot

Introduction

3-Tier architecture generally contains User Interface (UI) or Presentation Layer, Business Access/Logic Layer (BAL) and Data Access Layer (DAL).

Presentation Layer (UI)
Presentation layer is responsible for displaying the views. Contains windows forms or ASP.NET pages, where data is presented to the user or input is taken from the user. We will consider a sample Windows form application which will show the Authors information and details in the UI.

Business Access Layer (BAL) or Business Logic Layer

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

BAL contains business logic, validations or calculations related with the data

Business Entities

Business entities are reusable entities developed as per the application. We are making use of these entities in BAL and DAL. The data access layer fetches the data and converts the data say to a List of business entity. Ex: When we are retrieving a list of Authors details, the DAL will fetch all the authors and returns List<AuthorsBE> list of author’s business entities.

Data Access Layer (DAL)

DAL contains methods that helps business layer to connect the data and perform required action, might be returning data or manipulating data (insert, update, delete etc). For this demo pubs sample application, the BAL makes a call to data access to get all the list of authors i.e GetAllAuthors(), to get all the list of author titles GetAuthorTitleDetails(string authorID)

 

Advantages of N-Tier Application

  1. Decoupling the logic: By loose coupling the logics of Presentation, Business and Data access suppose if there is a change in the UI layer, you will only have to only about the modifications in the Presentation layer. Right now it is using SQL Server database so in future is there is a change in the database we will have to modify the logic with in the Data access layer and nothing else.
  2. With layered architecture you can do the software development in Parallel. That means you can code each layers independently
  3. Easy to Test: The testability of the software increases by decoupling the logics into multiple layers. You can independently Unit Test the logics of different layers
  4. Reusability of Components

 

 

How to run the sample:

  1. Download pubs database sample from http://www.microsoft.com/download/en/details.aspx?id=23654 link
  2. Install the MSI: SQL2000SampleDb.msi , run the scripts to create Pubs database.
  3. Download the sample project for this article from the below mentioned link for ‘Sample Project for Download’
  4. Open SQL Management studio and execute the stored procedures with in the DataAccessLayer – > Scripts folder in Pubs database.
  5. Open PubsSamplePresentation.sln Solution from VS 2010 or VS2011
  6. Go to PubsSamplePresentation and open App.config
  7. Change the connection string (PubsConnectionString) value appropriately
  8. Run the Windows Form application – PubsSamplePresentation

Sample Project for Download: PubsSamplePresentation

 

 


Leave a Reply