MVC Overview:
The MVC pattern is a software architecture in software engineering, the mode (model)-view (view)-controler (Controller) abbreviation;
The MVC pattern divides an interactive application into 3 components:
Model: The business logic layer that contains core functions and data and implements core business logic
View: Presentation layer, displaying information to the user
Controller: Control layer, process user input, and implement the view layer and model layer work together
MVC Application Areas:
Interactive application with flexible HMI:
Flexibility to choose different information display methods
Flexibility to choose the user input method
Different user interfaces are available for different user roles:
Different users have different permissions and operate differently
Model:
A business logic layer that encapsulates business logic and data
Business logic (core of software)
Data and the functions that access them (view components use)
Procedures for performing specific application processing (control calls on behalf of the user)
The model is not visible to the user (M vs. v Independent)
The model is independent of a specific output representation or Input method (M independent of C)
The user can only operate the model via the controller (c is the bridge between M and V)
Views (view):
The presentation layer, which is the interface that the user sees and interacts with, usually implements the input and output functions of the data.
Getting data from a model:
Implementation by State query function
Columns such as: Timed refresh
To display information to the user:
Different views use different methods to render information
Each view component has an update function that is activated by the model change notification
This function is used by the building block Oh (when the model has changed), the view is re-aligned with the model
In the initialization phase, the view registers the request change notification (table) with the model
Control (Controller):
Control layer, play the role of controlling the entire business process, realize the view layer and the model layer work together.
Each view has a related controller component (one by one corresponds)
Users only interact with the system through the controller
The controller component accepts events and translates them into inputs:
How events are sent to the controller is determined by the user interface platform
An event is translated into a plea for a model or view
If the behavior of the controller depends on the state of the model, then the controller also needs to register a plea change notification to the model
For example: The user clicks the button, the event response function of the button will respond to the action to process the user request
Change-Propagation mechanism:
A model can be used for multiple views:
If the user changes the data in the model through a view's controller, other views that depend on that data should also reflect this change
Once the model's data has changed, the model needs to notify all relevant views to make corresponding changes
Maintain consistency of data:
This can be done through the Observer (Observer) design pattern
The relationship and function diagram of the MVC component type:
The MVC mode of Android