In this article, we will discuss:
1. Three Tier (Three Layer) Architecture
2. Three Tier (Three Layer) Architecture VS MVC Pattern
3. How to use Three-layer architecture in Spring MVC web applications.
Learn Spring MVC at https://www.javaguides.net/p/spring-mvc-tutorial.html
Video
1. Three Tier (Three Layer) Architecture
2. Three Tier (Three Layer) Architecture VS MVC Pattern
- The Model Layer - This is the data layer which contains the business logic of the system, and also represents the state of the application. It’s independent of the presentation layer, the controller fetches the data from the Model layer and sends it to the View layer.
- The Controller Layer - The controller layer acts as an interface between View and Model. It receives requests from the View layer and processes them, including the necessary validations.
- The View Layer - This layer represents the output of the application, usually some form of UI. The presentation layer is used to display the Model data fetched by the Controller.
3. How to use Three-layer architecture in Spring MVC web applications.
In a Spring MVC web application, the three layers of the architecture will manifest as follows:- Controller classes as the presentation layer. Keep this layer as thin as possible and limited to the mechanics of the MVC operations, e.g., receiving and validating the inputs, manipulating the model object, returning the appropriate ModelAndView object, and so on. All the business-related operations should be done in the service classes. Controller classes are usually put in a controller package.
- Service classes as the business logic layer. Calculations, data transformations, data processes, and cross-record validations (business rules) are usually done at this layer. They get called by the controller classes and might call repositories or other services. Service classes are usually put in a service package.
- Repository classes as data access layer. This layer’s responsibility is limited to Create, Retrieve, Update, and Delete (CRUD) operations on a data source, which is usually a relational or non-relational database. Repository classes are usually put in a repository package.
- Presentation Layer - controller package
- Business Logic Layer - service package
- Data Access Layer - repository package
Conclusion
In this article, we have discussed:1. Three Tier (Three Layer) Architecture
2. Three Tier (Three Layer) Architecture VS MVC Pattern
3. How to use Three-layer architecture in Spring MVC web applications.
Read more about MVC pattern at Model View Controller (MVC) Design Pattern in Java
Continue Learning with Java Guides
Want to take your programming skills to the next level? Explore my practical Udemy courses on Java, Spring Boot, Microservices, Full-Stack Development, Docker, and Generative AI. You can also follow my structured learning roadmaps to become a professional developer.
By Ramesh Fadatare - Udemy Instructor Partner




Comments
Post a Comment
Leave Comment