Posted by Daljeet Singh | Last Updated: 07-Jan-19
Code Architecture is the way you organize and design the code for your application
.Itis important to organize and modularize your code into various sub-components as it helps promote separation of concern inside your code.
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
architecturedproperly. In addition to this, two of the most commonly faced problems arising out of a lack of proper code architecture are :
- 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
MVI(Model-View-Intent) .Eachof these patterns come with their own advantages and challenges for implementation.
MVIarchitecture bodes well with the reactive programming approach as the Model can be implemented as an Observer for the Intent and the View can be a Subscriber listening for any state changes in the model and also emit actions for the Intent to act upon.
If you want to start out with your first project using the
MVIpattern, the Mosby MVIlibrary might be a good fit for you as it contains pre-written library calls in RxJava and employs loose coupling between the UI and logic. Although there is not a lot of community support threads and documentation for MVIright now provides an efficient way of organizing your code particularly if your code utilizes the reactive programming paradigm. ,it