C# / .NET Compendium PLEN
.NET / C# / Refresher / web patterns

MVC vs MVVM vs MVP - a comparison of architectural patterns

The common denominator - separation of concerns

All three patterns solve the same basic problem: how to separate presentation logic from data and business logic, so the code is testable and easy to maintain. They differ in who knows about whom and exactly how communication flows.

MVC (Model-View-Controller)

User → Controller → Model
         ↓
       View (renderuje na podstawie Modelu)
  • The Controller receives the user's action, updates the Model, and chooses the View to display
  • The View renders data from the Model - in classic (web) MVC the View is generated anew on every request
  • The Controller knows about the View (it chooses which one to return) - this is an important difference compared with MVVM
// ASP.NET Core MVC - a classic example
public class OrdersController : Controller
{
    public IActionResult Details(int id)
    {
        var order = _orderService.GetOrder(id); // aktualizacja/pobranie Modelu
        return View(order); // Controller JAWNIE wybiera View i przekazuje dane
    }
}

MVP (Model-View-Presenter)

User → View → Presenter → Model
                ↓
              View (the Presenter EXPLICITLY tells the View what to display)
  • The View is passive (passive view) - it has no logic at all, it only exposes an interface through which the Presenter "drives" it
  • The Presenter contains all the presentation logic and explicitly calls methods on the View (e.g. view.ShowOrder(order)), instead of automatic binding
  • The View knows about the Presenter (to pass on events), and the Presenter knows about the View (through an interface) - two-way, but explicit communication
// The interface the View must implement
public interface IOrderView
{
    void ShowOrder(OrderDto order);
    void ShowError(string message);
}

public class OrderPresenter
{
    private readonly IOrderView _view; // Presenter WIE o View, przez interfejs
    private readonly IOrderService _service;

    public async void LoadOrder(int id) // an EXPLICIT call, not automatic binding
    {
        try
        {
            var order = await _service.GetOrderAsync(id);
            _view.ShowOrder(order); // the Presenter MANUALLY tells the View what to display
        }
        catch (Exception ex)
        {
            _view.ShowError(ex.Message);
        }
    }
}

MVVM (Model-View-ViewModel)

View ←→ ViewModel (through BINDING, not explicit calls)
           ↓
         Model
  • The ViewModel KNOWS nothing about the View (the key difference compared with MVP!) - communication happens through binding (INotifyPropertyChanged, ICommand), automatically, without explicit calls
  • This is exactly the model we discussed in detail with WPF - SetProperty → PropertyChanged → automatic UI update, without a manual view.ShowOrder(...)
public class OrderViewModel : ViewModelBase
{
    private OrderDto _order;
    public OrderDto Order // the ViewModel DOESN'T KNOW that any View exists at all
    {
        get => _order;
        set => SetProperty(ref _order, value); // an automatic notification, if ANYONE is listening
    }

    public async Task LoadOrderAsync(int id)
    {
        Order = await _service.GetOrderAsync(id); // po prostu ustawia property
        // NO method call on the View - the XAML binding updates itself
    }
}

The key difference between MVP and MVVM - who initiates the communication

This is the most commonly confused point in interviews - both look similar ("an intermediary between the View and the Model"), but they differ fundamentally:

MVP MVVM
Does the intermediary know about the View ✅ Yes (through an interface) ❌ No (no reference)
How the View updates The Presenter explicitly calls methods on the View Automatic binding (the View "observes" the ViewModel)
Testability of the Presenter/ViewModel Requires mocking the View interface Requires NOTHING View-related - pure logic
Typical framework Android (before Jetpack), older WinForms WPF, Xamarin.Forms, Angular (conceptually), Blazor (partly)

A summary table of all three

MVC MVP MVVM
Who chooses the View The Controller Nobody explicitly - the Presenter drives the existing View Nobody - the View "observes" the ViewModel
Who knows about whom The Controller knows about the View and the Model The Presenter and the View know about EACH OTHER (through an interface) The ViewModel does NOT KNOW about the View
The UI update mechanism A new render (web) / manual (desktop) Explicit method calls Automatic binding
Typical use ASP.NET Core MVC, Ruby on Rails Older Android, WinForms WPF, Blazor (partly), Xamarin

Why MVVM is so good for WPF - a link to the earlier discussion

This is exactly why our whole earlier discussion about DI/ViewModel testability worked so well - the ViewModel has NO dependency on the View, so unit tests of the ViewModel (as I showed with Moq) don't require launching WPF at all - there's no need to mock an IOrderView (as in MVP), because such an interface doesn't exist. This is a cleaner separation than MVP, at the cost that binding (the INotifyPropertyChanged + XAML mechanism) has to be provided by the framework (WPF; not every UI framework supports it natively).

Summary - a concise answer for an interview

All three patterns separate presentation logic from the Model; they differ in the direction and mechanism of communication with the View. MVC - the Controller explicitly chooses and renders the View. MVP - the Presenter explicitly calls methods on the View through an interface (the View and the Presenter know each other). MVVM - the ViewModel knows nothing about the View, communication goes through automatic binding (the View "observes" changes in the ViewModel) - this is the most "decoupled" model of the three, hence its popularity in WPF, where testing the ViewModel without a UI is crucial.

Buy me a coffee