What is MVC? What is a three-tier architecture?

What is MVC

MVC is an abbreviation of Model (Model), View (View), and Controller (Controller), and is a software design specification .
It is a method of separating business logic, data, and display to organize code.
The main function of MVC is to reduce the two-way coupling between view and business logic.
MVC is not a design pattern, MVC is an architectural pattern. Of course, there are differences in different MVCs.

Tips:
The two concepts of framework and design pattern are always easy to be confused, but there are still differences between them. **Framework is usually code reuse, while design pattern is design reuse, architecture is in between, part code reuse, part design reuse,** sometimes analysis can also be reused. There are three levels of reuse in software production: internal reuse, that is, abstract blocks that can be used commonly in the same application; code reuse, that is, combining common modules into libraries or tool sets so that they can be used in multiple applications and fields; application Reuse of frameworks, that is, providing common or ready-made infrastructure for specialized domains to achieve the highest level of reusability.

Model (model): data model, which provides the data to be displayed, so it contains data and behavior. It can be considered as a domain model or JavaBean component (including data and behavior), but now it is generally separated: Value Object (data Dao) and Service layer (behavior Service). That is, the model provides functions such as model data query and model data status update, including data and business.

View (view): Responsible for the display of the model, generally the user interface we see, what the customer wants to see.

Controller (controller): receives user requests, entrusts them to the model for processing (state change), and returns the returned model data to the view after processing, and the view is responsible for displaying. That is to say, the controller does the work of a dispatcher.

What is a three-tier architecture

Three-tier architecture The three-tier architecture in the usual sense is to divide the entire business application into: presentation layer (web layer), business logic layer (service layer), data access layer (persistence layer) . The purpose of distinguishing levels is the idea of ​​"high cohesion and low coupling" . In software architecture design, layered structure is the most common and most important structure. The hierarchical structure recommended by Microsoft is generally divided into three layers, from bottom to top: data access layer, business logic layer (or domain layer), and presentation layer.
image-20210628100810394
Definition of each layer

Presentation layer (Web layer): In layman's terms, it is the intuitive interface that users can see . Its function is to receive the request data submitted by the user, and to feed back the response data generated by the program to the user request to the user. The purpose is to provide users with an interactive operation interface. So, the presentation layer is like the building blocks that have been built.

Business logic layer (service layer): It is mainly for the operation of specific problems, and makes different responses according to different requests of users. It can also be understood as the operation of the data layer and the logical processing of the data business. If the data layer is a building block, then the logic layer is the construction of these building blocks .

Data access layer (persistence): It just provides a variety of ways to operate on the database, it is the operation on the database, not the data . Different data are like building blocks of different shapes, and the data access layer is like the action of taking or putting these building blocks back.

The MVC pattern can be seen as a subdivision and optimization of the presentation layer in the three-tier architecture .

image-20220621123407035

Guess you like

Origin blog.csdn.net/qq_41286824/article/details/125388779