Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MVVM vs MVP

Aydar
October 10, 2017

MVVM vs MVP

Presentation for the lightning talk on spikeweek at Freeletics

Aydar

October 10, 2017
Tweet

More Decks by Aydar

Other Decks in Programming

Transcript

  1. MVVM-C vs MVP
    Aydar Mukhametzyanov

    Dmytro Khmelenko

    View full-size slide

  2. View
    Controller
    Model
    Model-View-Controller

    View full-size slide

  3. Layout
    Activity
    View
    Controller
    Model
    Model-View-Controller

    View full-size slide

  4. View
    Controller
    Model
    Model-View-Controller

    View full-size slide

  5. UIViewController
    Model
    View
    Controller
    Model-View-Controller

    View full-size slide

  6. Problems with MVC
    Activity/UIViewController is a “God” class

    Business logic is mixed with UI

    Hard to reuse

    Hard to implement tests

    View full-size slide

  7. Solution
    Model-View-Presenter
    Model-View-ViewModel (+Coordinator)

    View full-size slide

  8. View
    Model
    (Interactor)
    Activity
    Layout
    Presenter
    MVP

    View full-size slide

  9. Solution
    Model-View-Presenter
    Model-View-ViewModel (+Coordinator)

    View full-size slide

  10. MVVM
    UIViewController
    Model
    View
    Controller

    View full-size slide

  11. Model ViewModel
    View
    UIViewController
    MVVM

    View full-size slide

  12. Model ViewModel
    View
    UIViewController
    UIView
    MVVM
    Navigation?

    View full-size slide

  13. MVVM stack
    Model
    ViewModel
    View
    Coordinator
    MVVM-C

    View full-size slide

  14. MVVM stack
    Coordinator
    MVVM stack MVVM stack
    MVVM-C

    View full-size slide

  15. MVVM stack MVVM stack
    MVVM stack MVVM stack
    Coordinator
    Coordinator
    MVVM-C

    View full-size slide

  16. View
    Model
    (Interactor)
    Activity
    Layout
    Presenter
    MVVM vs MVP
    Model ViewModel
    View
    UIViewController
    UIView

    View full-size slide

  17. • Provides data to Presenter/ViewModel

    • Processes data (networking, persistence)
    Model (Interactor)
    Responsibilities

    View full-size slide

  18. Responsibilities
    • Draws UI with provided data

    • Notifies Presenter/ViewModel about user actions
    View

    View full-size slide

  19. • Handles user actions from View

    • Gets data from Model

    • Updates data in Model
    • Business logic

    • Provides updated/processed data to View
    Presenter/ViewModel
    Responsibilities
    ———————————————————

    • Communicates with Coordinator

    View full-size slide

  20. • Handle navigation

    • Build the MVVM stacks
    Coordinator
    Responsibilities

    View full-size slide

  21. Same thing, different names?

    View full-size slide

  22. Bindings
    View
    ViewModel
    Owns
    Observes
    by Reactive approach

    View full-size slide

  23. Simulate bindings
    View
    ViewModel
    Owns
    Notifies
    To be continued…
    …with Reactive approach?

    View full-size slide

  24. Business logic is decoupled from UI

    Easy to maintain

    Easy to test

    Easy to reuse components
    MVP/MVVM-C advantages

    View full-size slide

  25. Thank you!
    Questions

    View full-size slide