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
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
- 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.
- With layered architecture you can do the software development in Parallel. That means you can code each layers independently
- 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
- Reusability of Components
How to run the sample:
- Download pubs database sample from http://www.microsoft.com/download/en/details.aspx?id=23654 link
- Install the MSI: SQL2000SampleDb.msi , run the scripts to create Pubs database.
- Download the sample project for this article from the below mentioned link for ‘Sample Project for Download’
- Open SQL Management studio and execute the stored procedures with in the DataAccessLayer – > Scripts folder in Pubs database.
- Open PubsSamplePresentation.sln Solution from VS 2010 or VS2011
- Go to PubsSamplePresentation and open App.config
- Change the connection string (PubsConnectionString) value appropriately
- Run the Windows Form application – PubsSamplePresentation
Sample Project for Download: PubsSamplePresentation