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 Slide

  2. View Slide

  3. View Slide

  4. View
    Controller
    Model
    Model-View-Controller

    View Slide

  5. Layout
    Activity
    View
    Controller
    Model
    Model-View-Controller

    View Slide

  6. View
    Controller
    Model
    Model-View-Controller

    View Slide

  7. UIViewController
    Model
    View
    Controller
    Model-View-Controller

    View Slide

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

    Business logic is mixed with UI

    Hard to reuse

    Hard to implement tests

    View Slide

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

    View Slide

  10. View
    Model
    (Interactor)
    Activity
    Layout
    Presenter
    MVP

    View Slide

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

    View Slide

  12. MVVM
    UIViewController
    Model
    View
    Controller

    View Slide

  13. Model ViewModel
    View
    UIViewController
    MVVM

    View Slide

  14. Model ViewModel
    View
    UIViewController
    UIView
    MVVM
    Navigation?

    View Slide

  15. MVVM stack
    Model
    ViewModel
    View
    Coordinator
    MVVM-C

    View Slide

  16. MVVM stack
    Coordinator
    MVVM stack MVVM stack
    MVVM-C

    View Slide

  17. MVVM stack MVVM stack
    MVVM stack MVVM stack
    Coordinator
    Coordinator
    MVVM-C

    View Slide

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

    View Slide

  19. • Provides data to Presenter/ViewModel

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

    View Slide

  20. Responsibilities
    • Draws UI with provided data

    • Notifies Presenter/ViewModel about user actions
    View

    View Slide

  21. • 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 Slide

  22. • Handle navigation

    • Build the MVVM stacks
    Coordinator
    Responsibilities

    View Slide

  23. Same thing, different names?

    View Slide

  24. Bindings
    View
    ViewModel
    Owns
    Observes
    by Reactive approach

    View Slide

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

    View Slide

  26. Business logic is decoupled from UI

    Easy to maintain

    Easy to test

    Easy to reuse components
    MVP/MVVM-C advantages

    View Slide

  27. Thank you!
    Questions

    View Slide