DevPrep

All topics › Software architecture

Why must the View in MVP be a protocol?

Middle PRO

The point

The Presenter in MVP updates the View, so it needs a reference to it. If that reference is a UIViewController, the Presenter:

So the View is described by a protocol — the set of commands the Presenter actually needs (show(count:), showError). That is DIP: the Presenter (high level) owns the abstraction; the controller (a detail) implements it.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store