What are the responsibilities of Model, View, and Controller?
In the MVC (Model-View-Controller) pattern, each part of the system has strictly defined responsibilities so the application stays clear, flexible, and manageable.
1. Model - application data and logic
Responsibilities:
- Stores and manages data (for example, users, orders, products).
- Implements the system's business rules and behavior.
- Handles requests from the controller: "save", "change", "find".
- Notifies the view about data changes (in some implementations).
Example:
A User class with register(), login(), change_password() methods and a users table in the database.
2. View - displaying data to the user
Responsibilities:
- Receives data from the model (through the controller).
- Builds the interface (HTML, JSON, an application window, a graphical element).
- Displays the result of the user's actions.
- Contains no processing or storage logic, only visualization.
Example: An HTML template of a user profile, a cart page, a PDF report, a React component.
3. Controller - connecting link and control logic
Responsibilities:
- Accepts user actions (a request, a click, a form input).
- Turns to the model to perform the needed action.
- Passes data to the view for display.
- Determines which view to use for the response.
Example:
The method UserController.show(id) gets the user from UserModel and passes it to the profile.html template.
Overall structure of the work:
User → Controller → Model → View → User- Controller: manages the process.
- Model: performs business logic and data work.
- View: shows the result.
Main principle:
Each component is responsible only for its own task. The controller manages, the model knows how to work, and the view knows how to show.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.