The previous article gave a brief overview of the MVC framework pattern and, at the end of the article, gives a logical diagram of how MVC3 components work with each other, and in this article we'll go further to model-view-controller Their respective concepts and the principles of their co-operation.
models (model)
- Business logic. Encapsulates the 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 (Controller calls on behalf of the user)
- The model is not visible to the user (M and v are independent)
- Model independent with specific output representation or input mode (M vs. C Independent)
- The user can only operate the model via the controller (c is the bridge between M and V)
views View
- The presentation layer. is the interface that the user sees and interacts with, and usually implements the input and output functions of the data.
- Get the data from the model. Implemented by State query functions (e.g., timed refresh)
- Displaying information to users
- Different views use different methods to render information
- Each view component has an update function that is activated by the model change notification
- Once the function is activated (the model has changed), the view will be re-aligned with the model
- During the initialization phase, the view enlists the model to request a change notification
controller Controllers
- Control layer. Play the role of controlling the whole business process, and realize the collaborative work between view layer and model layer.
- Each view has a related controller component (one by one corresponds)
- Users only interact with the system through the controller
- The controller component receives the event and translates it into an input
- How events are sent to the controller is determined by the user interface platform
- The event is translated into a request 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 the request change notification to the model (for example: the user clicks the button, the button's event response function will take appropriate action to process the user request)
Change - propagation mechanism
- A model can correspond to 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 approach can be done through the Observer (Observer) design pattern
MVC framework Pattern (ii)