Ravinder Singh

Male
Friday, February 24, 1984
I am a software engineer by profession and programmer by passion. I love working on software projects which help make a positive impact on the society.

What is N-Layer architecture

Category: Programming Tutorials Date: Wednesday, June 21, 2017
OpenESchool Emagazine

A software architecture defines how you logically or physically separate different modules of your project. It helps you write manageable code so that you do not end up making your code ugly and filled with errors. As a beginner you should at least learn to separate your code into two layers

  1. UI layer
  2. Logic layer

Separating your code into different layers could mean many things.

  1. It can mean that you have different functions to handle the UI related code and for logic related code.
  2. It can mean that you have different classes which handle the UI related code and logic related code.
  3. It can mean that you have two different projects, one for UI related code and the other for logic related code.

Depending on the type and complexity of your software project you can select how your want to logically separate your code into different layers.

N layer architecture

N layer architecture is one of the most commonly used term in the software world. This means that an application has been logically divided into multiple layers, each layer responsible for performing a given operation. Most of the time you will find that applications are divided into 3 layers

  1. UI or Presentation layer
  2. Business logic layer
  3. Data access layer

Each of these layers have their own special roles. The UI layer is responsible for communicating with the user. This includes getting inputs from the user and displaying the results back to the user. The data access layer is responsible for performing the database related operations, like inserting, reading, updating and deleting records from a database table. The business logic layer is responsible for performing the logical operations. For example, if you have records for all employees in a company and you want to prepare a report which shows the details of monthly leaves for all employees, then the logic which you have to apply to prepare this report will be added in the business logic layer.

When you divided your project code into the above 3 layers we call it as a 3 layer architecture. Depending on the complexity of a software application there can be many more layers apart from the 3 layers discussed above.

Communication between layers

In an N layer architecture different layers communicate with each other by calling functions in other layers. For example, if the business logic layer wants to delete a record from the database table, it will call the Delete function in the data access layer. Normally the layers should communicate with each other in a single direction. For example, the UI layer should communicate with the business logic layer and the business logic layer should communicate with the data access layer. The UI layer should never communicate directly with the data access layer by bypassing the business logic layer or the data access layer should never communicate directly with the business logic layer. This way we can maintain a healthy separation of concerns between different layers in a software application.

When you start building your software applications, you should always try to follow the N layer architecture for your projects.

 

Rate this article and help us improve

Please Login to rate
Overall ratings: 0 | Rating: out of 5
Next Article

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp