Monday, January 16, 2012

3 Tier Architecture in .NET C#



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

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 worry about the modifications in the Presentation layer. Right now it is using SQL Server database , if in future you are changing your mind in is using other databases , we will only have to modify the logic within the Data access layer and nothing else is required.
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.    Re usability 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)   Open SQL Management studio and execute the stored procedures with in the DataAccessLayer - > Scripts folder in Pubs database.
3)   Open PubsSamplePresentation.sln Solution from VS 2010 or VS2011
4)   Go to PubsSamplePresentation and open App.config
5)   Change the connection string (PubsConnectionString) value appropriately
6)   Run the Windows Form application (PubsSamplePresentation)


No comments:

Post a Comment