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

Android VIPER Architecture implementation

Jiri Helmich
November 24, 2016

Android VIPER Architecture implementation

How to implement VIPER aka Clean Architecture on Android

Jiri Helmich

November 24, 2016
Tweet

Other Decks in Education

Transcript

  1. VIPER
    ON ANDROID
    Jirka Helmich

    View Slide

  2. VI-WHAT?

    View Slide

  3. VIPER LAYER STRUCTURE
    ● 5 organized layers
    ● Single responsibility
    ● Easy to read
    ● Mid to huge projects

    View Slide

  4. VIEW
    Should take care of following:
    ● UI rendering
    ● UI components
    ● Data displaying
    ● Should wrap main View objects and provide them to lower levels
    ● Android API specific stuff which does require Activity Context

    View Slide

  5. PRESENTER
    This layer should behave like a bridge between UI and it’s data.
    It should:
    ● Handle UI events
    ● Update UI based on events
    ● Communicate with ViewModel to update / gather data
    ● Should use Data Binding framework

    View Slide

  6. VIEWMODEL
    This layer should hold View state and data.
    It should take care of:
    ● View state operations
    ● Persist over UI configuration changes
    ● View related data operations
    ● Should use Observer pattern to notify changes

    View Slide

  7. INTERACTOR
    This layer should operate with all the business logic data necessary for the ViewModel
    and should push them there.
    Should take care of:
    ● Data operation to / from various data sources
    ● ViewModel-ready data preparation

    View Slide

  8. ENTITY
    Basically an POJO object which should describe business logic related objects.

    View Slide

  9. ROUTER
    Basically an utilized class to handle screen related navigation. Therefore any Fragment
    or Activity starting / showing / hiding operations.
    Similar to Navigator pattern.

    View Slide

  10. BUT WHY?

    View Slide

  11. MOTIVATION
    Why should I choose VIPER architecture for my project?
    ● Good modularization
    ● Concern separation
    ● SOLID principles
    ● Clean to read and understand
    ● High testing ability (good for TDD)

    View Slide

  12. “It is not enough for code to work.“
    ROBERT C. MARTIN,
    Clean Code: A Handbook of Agile Software Craftsmanship

    View Slide

  13. DIFFERENCES

    View Slide

  14. Differences against MVVM
    ● More abstraction
    ● Best for more complex projects
    ● Overkill for simple applications
    ● More layers thus better concern separation
    ● Better testability

    View Slide

  15. TIME COMPLEXITY
    - It is really complex to implement it.
    - You should be patient and careful
    when building the base.
    - If you are going for a huge project.
    => Don’t reinvent the wheel.
    http://www.memes.com/img/635087

    View Slide

  16. TESTING

    View Slide

  17. TESTING
    Interactor and ViewModel
    ● JUnit || Roboelectric (unit tests)
    View and Presenter
    ● Espresso (UI tests)

    View Slide

  18. HOW TO?
    Simple Weather App Example

    View Slide

  19. YOU WILL LOVE IT... ONCE YOU UNDERSTAND
    https://cdn.meme.am/instances/500x/34367767.jpg

    View Slide

  20. DEMO PROJECT
    ● https://github.com/Helmisek/android-viper/tree/master/sample
    ○ Android VIPER architecture
    ○ Data binding
    ○ RxJava
    ○ Retrofit
    ○ GSON

    View Slide

  21. SOURCES
    ● https://github.com/Helmisek/android-viper
    ● https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-architecture.html
    ● http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/
    ● https://realm.io/news/360andev-richa-khandelwal-effective-android-architecture-
    patterns-java/

    View Slide

  22. THANK YOU
    @jirkahelmich, @strvcom

    View Slide

  23. QUESTIONS

    View Slide