In this post we will be discussing about the N-Tier architecture and its importance. First let us see the difference between Tier and Layer.
· Tier usually means the physical deployment computer.
- Layer usually means Logic software component or Logical separation of code which may or may not run in same process or same machine.
- Tier are places where Layers are deployed and executed.
- Layer and tier may or may not exactly match each other. Each layer may run in an individual tier. However, multiple layers may also be able to run in one tier.
Types of Layers:
1. Presentation Layer: Desktop UI, Web Page or Mobile App
2. Application Layer: Business Logic and Data Validations. Also called as Middle Layer
3. Data Layer: External datasource like Sql Server, Oracle,
Types of Tier’s:
1. 1-Tier: All the 3 layers are in same process running in one machine. Embeded database like MS-Access, dbase etc are supposed to be used.
2. 2-Tier: Either presentation layer and application layer will run in one computer or application layer and data layer can only run in one computer.
3. 3-Tier: Its the simplest case of N-Tier architecture. All three layers will run in three separate computers.
4. N-Tier: 3 or more tiers architecture. Some layers in 3-tier architecture can be broken into many layers eg: Application Layer = Business Layer + Persistance Layer. This is ideal implemented for Web Based application.
Overview of Each Layer:
1. Client layer: this layer is involved with users directly. There may be several different types of clients coexisting, such as WPF, Window form, HTML web page, Mobile App etc.
2. Client presenter layer: contains the presentation logic needed by clients, such as ASP.NET in IIS web server.
3. Business layer: handles and encapsulates all of business domains and logics; also called domain layer. Can be implemented using WCF.
4. Persistence layer or DAL: Handles the read/write of the business data to the data layer.
5. Data layer: the external data source, such as a SQL Server or Oracle database.
Advantage of N-Tier architecture: Better Scalability, Finer security control, Better fault tolerance ability, independent tier upgrading without affecting other tiers, friendly and efficient development, friendly maintenance and better reusability.
We should differ the following two cases:
a) All layers run in one process of a computer: 1 tier architecture
b) All layers run in different processes of a computer = N-Tier architecture but deployed in just 1 host.
N-Tier – Architecture (Logical Separation)
- Tables, Views, Indexes and other database schema
- Stored Procedures, Triggers implementing logic pertaining to data in the tables.
- A utility class provided by Microsoft encapsulating the functionality of binding ADO.NET objects for communicating with SQL – Server.
- These objects are mostly mapped to the database tables. The columns of the table are represented as fields in these objects.
- These objects are also responsible for validating data in the properties encapsulating the field members.
- Here we can additional properties whose value will be dependent on other fields of the same object.
Data Access Objects (DAO)
- These are objects used for performing Create, Retrieve, Update & Delete (CRUD) operations over the database schema.
- This class mostly encapsulates the Stored Procedures in the database.
- The methods here are generally static and they either get input as parameter or return output in the form Data objects.
- These objects can also handle database specific exceptions and throw them as application specific exceptions.
- These objects shield all the complex logic of the business from the presentation tier.
- They may use one or more DAO objects for performing CRUD operations in the database.
- Business objects if required should start Transactions.
- For every action one new method can be added to this class.
- GUI of the application – Interactivity with the end user.
- Validation of data entered in various controls.
- Handle exceptions and prompt the user about the same.
Very much valuable knowledge to share.