MVC
What is it?
MVC is a pattern that organizes an app into three parts: the Model (data), the View (display), and the Controller (logic that connects them).
Explain like I'm 5
Why was it created?
Mixing data, display, and logic in one place becomes a tangled mess. MVC was created to separate these concerns so code stays organized.
Where is it used?
- Web application frameworks
- Desktop and mobile UIs
- Organizing app code
- Separating display from logic
Why should developers care?
MVC underpins many web frameworks, so understanding it helps you navigate and structure real applications.
How does it work?
The Model manages data and rules; the View renders what the user sees; the Controller handles input, updates the Model, and selects the View. Keeping them separate makes each easier to change and test.
Real-world example
A web request hits a Controller, which loads data from the Model and passes it to a View that renders the HTML page.
Common use cases
- Structuring web apps
- Separating UI from logic
- Organizing UI codebases
- Making code testable
Advantages
- Clear separation of concerns
- Easier to maintain and test
- Parallel work on UI and logic
- Widely understood
Disadvantages
- Can be overkill for tiny apps
- Boundaries blur in practice
- Controllers can grow bloated
- Variants cause confusion
When should you use it?
When organizing an app with a user interface and meaningful logic.
When should you avoid it?
For trivial scripts or when a different architecture fits the app better.
Alternatives
Related terms
Interview questions
Beginner
- What do M, V, and C stand for?
- Why separate them?
Intermediate
- What goes in a controller versus a model?
- How does MVC aid testing?
Senior
- How do you keep controllers from becoming bloated?
- How does MVC compare to MVVM?
Common misconceptions
- "MVC is a framework" — it's a design pattern that many frameworks implement.
- "Business logic belongs in the controller" — core logic usually belongs in the model layer, not the controller.
Fun facts
- MVC stands for Model-View-Controller.
- It originated in desktop UI work in the 1970s, long before web frameworks adopted it.
Timeline
- 1970s — MVC pattern first described for UI software
Learning resources
Quick summary
MVC organizes an app into Model (data), View (display), and Controller (logic), separating concerns for cleaner, more testable code.
Cheat sheet
- Model = data, View = display, Controller = logic
- Separation of concerns
- Common in web frameworks
- Keep logic in the model