Software Engineering basics - Layered Model (Layered Architecture)

Layered Model (Layered Architecture)

Definition:
The Layered Model is a software architectural style in which a system is organized into layers, each with a specific set of responsibilities.
Each layer provides services to the layer above it and uses services from the layer below it.

This model promotes modularity, maintainability, and separation of concerns.


Key Idea

  • The system is divided into hierarchical layers.

  • Each layer performs specific functions and communicates only with adjacent layers.

  • Changes in one layer have minimal impact on other layers.


Typical Layers in a Software System

Layer Function
Presentation Layer Handles user interface and interaction (UI, input/output).
Application / Business Layer Contains business logic, rules, and workflows.
Data Access Layer Provides access to databases or external data sources.
Database / Storage Layer Stores persistent data (DBMS, file system).

Diagram of Layered Architecture

+---------------------------+
|   Presentation Layer      |  <-- User Interface
+---------------------------+
            |
            v
+---------------------------+
|   Business Logic Layer    |  <-- Application Rules
+---------------------------+
            |
            v
+---------------------------+
|   Data Access Layer       |  <-- Database Communication
+---------------------------+
            |
            v
+---------------------------+
|   Database / Storage      |  <-- Persistent Data
+---------------------------+

Explanation of Data Flow:

  1. The user interacts with the presentation layer (UI).

  2. The presentation layer sends requests to the business logic layer.

  3. The business layer processes the request and accesses the data access layer to retrieve or update data.

  4. The data access layer communicates with the database to perform storage/retrieval operations.

  5. Results flow back up through the layers to the user.


Advantages of Layered Model

  1. Modularity: Each layer is independent and can be developed separately.

  2. Ease of Maintenance: Changes in one layer rarely affect others.

  3. Reusability: Layers (like data access or business logic) can be reused in different applications.

  4. Separation of Concerns: Each layer has a well-defined responsibility.

  5. Scalability: Layers can be distributed across servers if needed.


Disadvantages

  1. Performance Overhead: Data passes through multiple layers, which can slow down processing.

  2. Rigidity: Tight coupling between layers may restrict flexibility.

  3. Complexity in Debugging: Tracing errors through multiple layers can be difficult.

  4. Overengineering for Small Systems: Not always suitable for small or simple applications.


Example

Online Shopping System:

  • Presentation Layer: Web or mobile app UI.

  • Business Layer: Cart management, payment processing, order validation.

  • Data Access Layer: Queries product and user information from database.

  • Database Layer: Stores product catalog, user accounts, and orders.