Employing the MVI Pattern for your Android Application
Posted By Daljeet Singh | 31-Oct-2018
Code Architecture is the way you organize and design the code for your application
The need for an architecture pattern
Architecting is especially important as your application code undergoes a lot of changes over a period of time, and these changes can leave your code in a pool of mess if the code is not
- Testability: Unit testing various parts of your code gets pretty tedious. Also using a Dependency Injection library like Dagger2 to reduce code coupling becomes virtually impossible.
- Maintenance: Code maintenance and addition/removal of functionalities become quite cumbersome.An increase in the time required to debug and resolve issues arising out of the code.
Because of the aforementioned issues, it becomes essential that we adhere to a coding architecture while writing code for our application. Some of the popularly used patterns for architecting android code are MVC(Model-View-Controller), MVP(Model-View-Presenter), MVVM(Model-View-ViewModel) and
Intent :An Intent describes the intention of the user while interacting with the app .TheIntent receives the input from the user in the form of UI events(e.g button clicks ,fieldinputs) and translates it before delivering it to the Model in a manner that can be processed and understood by the Model. Model :The Model in MVIis immutable and responds to the Intent events .EachModel represents a state inside the app and a new instance of the model is created for every change of state triggered by the Intent events. View :The View represents the actual UI of the app .Itobserves the Model and propagates any changes in the state of the Model to the UI.
If you want to start out with your first project using the