How does MVVM differ from MVP?
The point
Both patterns move logic out of the controller into a separate object. The difference is the direction of the link between that object and the View:
- MVP: the Presenter knows the View (through a protocol,
weak) and imperatively commands it:view.showLoading(true),view.render(rows:). The View is passive. - MVVM: the ViewModel does not know the View. It publishes observable state (
rows,isLoading), and the View subscribes and re-renders itself. The link is a binding.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep