Design Patterns interview question · Most asked
What is MVC, and which design patterns does it combine?
Summary
Model-View-Controller separates data and business rules (model), presentation (view) and input handling (controller). Classic MVC combines Observer (views observe the model), Strategy (the controller is the view's strategy for handling input) and Composite (nested views).
Longer Answer
Web frameworks (Rails, Laravel, Django's MTV, Spring MVC, ASP.NET MVC) adapt it: a controller handles an HTTP request, works with models, and renders a view or JSON. Variants include MVP and MVVM (data binding in Vue, Angular, WPF).
The common pitfall is fat controllers; move business logic into models or services.
Key Points
- Model, view, controller separation.
- Built from Observer, Strategy and Composite.
- Web MVC is a request-based adaptation.
- Avoid fat controllers.
Explanation
What interviewers look for
Responsibilities of each part and awareness of the underlying patterns.
More most-asked Design Patterns questions
- What problem does the Builder pattern solve? Show an example.
- Explain the SOLID principles.
- What is a design pattern, and why are they useful?
- What is the difference between dependency inversion, dependency injection and inversion of control?
- Why is composition often preferred over inheritance?
- What is dependency injection, and what forms does it take?
- Explain the Factory Method pattern and how it differs from a simple factory.
- How do you implement a Singleton, and why is it often considered an anti-pattern?