
P


MVC is a foundational software design pattern used in web and UI applications to separate responsibilities across components. Interviewers ask about it to evaluate your understanding of architecture, maintainability, and clean separation of concerns.
Explain the Model-View-Controller (MVC) design pattern. In your answer, cover:
You do not need to describe a specific framework in depth, but you should explain the pattern clearly enough to apply it in a real application. A strong answer should distinguish responsibilities, describe a typical request lifecycle, and mention common misconceptions such as putting too much business logic in controllers or views.
The Model represents the application's data and business rules. It is responsible for state, validation, and domain behavior, and it should not depend on presentation details.
class User:
def __init__(self, name):
self.name = name
def rename(self, new_name):
if not new_name:
raise ValueError('name required')
self.name = new_name
The View is the presentation layer that renders data for the user. It should focus on display logic, not core business decisions or data persistence.
def render_user(user):
return f'<h1>{user.name}</h1>'
The Controller handles input or requests, coordinates work between the Model and the View, and decides what response to return. It acts as the mediator between user actions and application behavior.
def show_user_controller(user):
return render_user(user)
MVC divides responsibilities so that data logic, request handling, and presentation are not tightly coupled. This improves maintainability, testing, and team collaboration because changes in one area are less likely to break another.
In a typical web app, a user action reaches the Controller first, which updates or queries the Model, then passes data to the View for rendering. Understanding this flow is key to explaining MVC correctly.
Request -> Controller -> Model -> View -> Response