Introducing the app's architecture
In this section, we will discuss the most common architecture that can be applied to an Android application and how it can be combined with clean architecture principles, and see how we should ideally structure our code base.
In the exercises from the previous chapters, we saw how, for an application that requires the integration of multiple data sources for networking and persistence, we had to put a lot of logic inside the ViewModel
class. In those examples, ViewModel
had multiple responsibilities, including fetching the data from the internet, persisting it locally, and holding the required information in the user interface. On top of these extra responsibilities, ViewModel
also had many dependencies on the different data sources; this means that a change in the networking or persistence libraries would require a change in ViewModel
. To solve this problem, our code would need to be split into separate layers with different responsibilities...