15.2 · Coordinators, routers and dependency injection

Two questions shape the codebase more than the choice of UI pattern: who decides which screen comes next, and who decides which object a screen talks to.

Mental model. Screens should report what happened and receive what they need. Someone else decides where to go next and what to hand over.

Who navigates

Coordinators and routers versus SwiftUI navigation.

  1. What is a coordinator or router, and how does it compare with SwiftUI’s NavigationStack for deciding who owns navigation? 15.2.1 · L3
    If each screen decides where to go next, screens know about each other and cannot be reused, tested or reordered. A coordinator (or router) takes that job: a…

Who provides

Dependency injection without a framework religion.

  1. How do you do dependency injection in Swift, and when do you need a container or framework? 15.2.2 · L3
    Dependency injection (DI) means an object receives the things it depends on instead of creating or looking them up itself. The benefits are testability…

More in Architecture & API design