Slide 1

Slide 1 text

MVI Architecture Model View Intent in Android

Slide 2

Slide 2 text

Contents Introduction Features of MVI Why MVI? MVI Components Boilerplate QnA

Slide 3

Slide 3 text

Introduction Model holds single or multiple dynamic data structures and the business logic associated with it. View, same as other architecture patterns, is the interface for displaying/rendering information to the end user by listening to the outputs of the model or state. Intent (≠Android Intents) is an action or event from either the end user interacting with the user Interface or the system with a desired result. And, Last but not the least, User; Either the actor interacting with the software system or the system itself. user(view(model(intent(user()))))

Slide 4

Slide 4 text

What is MVI? A reactive architecture pattern where the model is updated based on some interactions from user or the system and the view is updated based on states emitted from the model. Finite State Machine (FSM) Consider this to be finite state machine that has a limited or finite no of possible states.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Why MVI? - One of the integral part of MVVM architecture is the ViewModel. - Nevertheless, the concept of model defined in MVC pattern is not being followed religiously. - The view is not driven by the model, directly. View can observe multiple observable properties from ViewModel for state changes which causes state overlapping issues - Sometimes two different states are shown unexpectedly, both error and loader state).

Slide 7

Slide 7 text

The State Overlapping problem MVI pattern solves the state problem by adding the actual ‘model’ layer which is observed by view for state changes. As this model is an immutable and single source of truth for the current view state, overlapping of states will not happen.

Slide 8

Slide 8 text

Unidirectional One of the core concepts of MVI is Unidirectional Data flow. Some of the benefits of unidirectional flow are: 1. It reduces Edge Cases. 2. It solves the State Problem. 3. It enforces Single Responsibility Principle (refer S.O.L.I.D Principles). Hence, MVI provides a more decoupled architecture pattern.

Slide 9

Slide 9 text

Single Immutable State MVI also provides a Single Immutable State which is more predictable. Also, it simplifies logic surface, enhancing maintainability and testability of the project. With Single Entry and Exit Point, MVI also consolidates points for : 1. Validation 2. Analytics collection 3. Debugging.

Slide 10

Slide 10 text

Reactive MVI is based on reactive mechanism. The action performed by the user/system are considered as a part of MVI architecture. In layman terms, our View observes and reacts to any change in the state of the model as a result of some action either by the user or the system.

Slide 11

Slide 11 text

The Key Components ViewState

Slide 12

Slide 12 text

The Key Components ViewEffect

Slide 13

Slide 13 text

The Key Components ViewEvent

Slide 14

Slide 14 text

Data Flow in MVI using LiveData

Slide 15

Slide 15 text

The ViewModel (Reducer)

Slide 16

Slide 16 text

Manipulating the ViewState and ViewEffect

Slide 17

Slide 17 text

The View

Slide 18

Slide 18 text

The BaseView

Slide 19

Slide 19 text

Final Verdict We have learnt about the MVI principles, components and finally the boilerplate with Android LiveData based approach. It may seem like adding more complexity than straight forward processing of the actions. But, in the long run, it will pay off as debugging cum tracking down the root cause of any issue/crash will be super easy as we can add or track new features easily.

Slide 20

Slide 20 text

That’s it for today... Time for QnA