Modular Programming in Android with MVVM (Kotlin) — Part 1
This story describes basics of modularization of mobile application during development with sample application.
What is Modularization ?
Modularizing your app is the process of separating logical components of your app project into discrete modules.
Reorganizing your app into separate logical components requires considerable amount of time, but it has following advantages:
(1)Develop in Parallel : By separating logical components of your app into modules, different teams or individuals in your organization can take ownership of each module and work on them with fewer merge conflicts or disruptions to other teams. Additionally, if you have logic that’s used in various parts of your app, you can use library modules to promote code reuse and encapsulation.
(2)Improve build times:The build system is able to build multiple modules in parallel and significantly reduce build times. The more modular your project is, the more significant the build performance improvement becomes.
(3)Customize feature delivery:Modularizing your app’s features as dynamic feature modules is a requirement to take advantage of Dynamic Delivery’s such as ondemand,instantapp .
Note: Modularizing your project by app features takes time and consideration to do properly. When you do decide to begin modularizing your app, you should first configure your base module with the properties necessary to support modular features.
Different ways of Creating Modules:
(1) First Approach : Modules can added from Android studio by going through File->New-> NewModule. We can add as many modules as possible. All the modules will be in the same project and can communicate .
Advantage: The advantage is modules can be modified easily and results can be observed instantly.
Disadvantage: However this approach does not provide benefits of modularization as modularization means manageable small projects, separate commonly code used and logic. In this approach as all the source code is in the same project it is not suggested approach to go for modularization.
(2) Second Approach: In this approach we create modules as libraries and use them as dependencies when needed. We can create modules separately and upload them is server and use them as dependency to build.gradle file.With this approach once we develop a library , we can use it as dependency also can be re-used in other projects as well which reduces development effort.
Part -2 :