Multitier Applications
Definition
A Multitier Application (also known as N-tier architecture) is a software engineering design pattern that separates an application into distinct logical and physical layers. In the context of Advanced Java, this architecture typically divides the system into the Presentation Tier, Business Tier, and Data Tier, allowing each to be developed, maintained, and scaled independently.
Main Content
1. Presentation Tier (Client Layer)
- This is the top-most layer that interacts directly with the user. In Java, this often involves JSP (JavaServer Pages), JSF (JavaServer Faces), or a frontend framework (React/Angular) communicating with a Java REST API.
- Its primary responsibility is to display information and collect user input while remaining decoupled from business logic.
2. Business Tier (Application/Logic Layer)
- This is the "brain" of the application where core processes and calculations occur. In Java, this is usually managed by Enterprise JavaBeans (EJB) or Spring Beans.
- It enforces business rules, processes data, and orchestrates communication between the UI and the database.
3. Data Tier (Persistence Layer)
- This tier manages the storage and retrieval of data. It usually consists of a Database Management System (DBMS) like MySQL, PostgreSQL, or Oracle.
- It uses Java persistence technologies like JPA (Java Persistence API) or Hibernate to map Java objects to database tables (ORM).
Working / Process
1. User Request Initiation
- The user interacts with the user interface, such as clicking a button or submitting a form.
- The request is encapsulated (often as an HTTP request) and sent to the Web Server or Application Server.
2. Business Logic Execution
- The Application Server receives the request and triggers the corresponding Java code in the Business Tier.
- The logic validates the request, performs necessary calculations, and decides if a database operation is required.
3. Data Persistence Interaction
- The Business Tier communicates with the Data Tier to fetch or update records using SQL queries or ORM frameworks.
- The result flows back through the layers, ultimately rendering a response back to the user.
[ Presentation Tier ] (Browser)
|
v
[ Business Tier ] (Java Server/Spring)
|
v
[ Data Tier ] (Database)
Advantages / Applications
- Scalability: You can scale each tier independently; for example, adding more database servers without changing the UI code.
- Maintainability: Changes in one tier (e.g., updating the database schema) do not necessarily require changes to the user interface.
- Security: The database is not exposed directly to the client; all requests must pass through the Business Tier, acting as a security firewall.
- Reusable Components: Business logic can be shared across multiple clients, such as a web browser and a mobile app, simultaneously.
Summary
Multitier architecture is a structural design that splits application functionality into distinct layers: Presentation, Business, and Data. By decoupling these components, developers gain significant improvements in system scalability, security, and maintenance.
Important terms to remember: - Separation of Concerns: Dividing software into distinct sections to handle specific tasks. - ORM (Object-Relational Mapping): The technique of mapping Java objects to database tables. - Scalability: The ability of a system to handle increased workloads.