2

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?

swalkner
  • 16,679
  • 31
  • 123
  • 210

1 Answers1

0

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.

Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
  • 1
    Your answer is very subjective, because it can be argued that screen transition is not part of business logic, but application logic. https://softwareengineering.stackexchange.com/questions/293885/what-is-the-difference-between-business-and-application-logic Also it can be argued that business logic belongs to the Model, not the ViewModel. https://stackoverflow.com/questions/37671866/should-i-implement-business-logic-on-a-model-or-a-viewmodel – Edudjr Jul 06 '20 at 11:46