Wednesday 12 September 2012

Layers and Tiers

Layers and Tiers are the terms which are often used interchangeably while developing software. However, to be more precise, layers are logical grouping of software components that make up the application. Tiers refer to the physical residence of those layers.

Layers
=================================
We partition an application into layers such that each layer performs a specific type of functionality and communicates with the layer that adjoin it. This helps in maintenance as well as makes it easier to add new features to the application.
(We can perform layering by putting different types of classes into different packages).

However, there is no upper limit of number of layers an application can have. Each layer can also be further break down into several layers depending upon the requirements and size of the application. But most commonly used layered architecture is based on three layers. These are: Presentation Layer, Business Layer and Data Layer.


Here, users can only interact with presentation layer. The presentation layer passes the user request to the business layer, which further passes the request to the data layer. The data layer communicates with the data sources (like Database etc.):

1) Presentation Layer

It provides a user interface to the client to interact with the application. This is the only part of the application visible to client. Its job list includes collecting user’s input, validating user’s input (on client side using JavaScript like technologies OR on server side), presenting the results of the request made by the user and controlling the screen flow.

2) Business Layer

It is only concerned with the application specific functionality. It is used to implement business rules and to perform business tasks. For example, in a accounting system, this layer will provide the functionality of transferring of balance from one account to another, calculation of taxes etc...

3) Data Layer

It is responsible for management of the data & data sources. Data sources can be database, XML, web services, flat file etc. Both, data retrieval & storage logic is coded inside this layer.

Tiers
=================================
Due to layered architecture, it is easier to build a tiered architecture. Like layers, there is no restriction on using number of tiers. We can build application based on Single-tier, Two-tier, Three-tier or N-Tier. It mainly depends upon business requirements and size of the application.

Tiers are physically separated from each other (on different machines) and then we spread layers across tiers to build up an application. Two or more layers can reside on one tier. The following figure presents a three-tier architectural view of an application:


Client tier: The client tier represents the client machine where actually web browser is running and usually displays HTML.
Presentation has two parts; one is on client side, for example, HTML. There is also a presentation layer that is used to generate the client presentation often called server presentation.

Middle tier: The server machine can consist on a single server machine or more. Therefore, it is possible web server is running on one server machine while application server on another. Both, web and business tiers can be grouped as middle tier.
Web server is used to execute web pages like JSPs whereas application server is used to run business objects like EJBs.

EIS tier: The database server is often running on a separate tier, i.e. DB machine often called Enterprise information tier.










No comments:

Post a Comment