MVVM-C: why connecting Coordinator to ViewModel instead of View?

Viewed 553

I read a lot of blog posts about MVVM-C (Swift, especially), and always a navigation is triggered View => ViewModel => Coordinator.

Wouldn‘t it be easier to have a reference between View(Controller) and Coordinator to avoid the intermediate step with the ViewModel? What‘s the reason the View(Controller) must not know about the Coordinator?

1 Answers

I agree with above answer, but would like to add some more reasoning:

Following Single responsibility from SOLID, ViewController which is View in MVVM should not be responsible for screen transitions and notifying of Coordinator that a transition should occur.

Screen transition is a part of business logic. So it can be triggered in ViewModel and that is a good place for it.

Related