Having a clean approach is a must in every project.

When I started developing Android apps back in 2014 like everybody else I would put everything about a screen in one class. This is the so-called God class approach (God Activity approach in Android). It’s called that way because there is one single class that is responsible for everything that a screen has to handle: fetching the data from backend and/or from a local database and displaying it on the screen in an user friendly way.

Although the code was working fine, when I had to come back to a class that I had not worked on in a month I would always hate myself because of writing it. The screens would usually have 1500–2000 lines of code. And in order to add a new feature or fix a bug, I would have to go through all of those lines to make sure that I’m not breaking anything else. It was a big messy hairy blob of spaghetti code!

Photo by Eiliv-Sonas Aceron on Unsplash

Back in 2014, there was nothing mentioned in the official documentation about architecture. Google were silent so if you wanted to use a clean approach for building your app, you had to dig through a lot in order to find that.

As the years went by, I started following the Android Development sub in Reddit where I got exposed to the newest trends and best practices. In 2015 and 2016 the community was mainly using Model-View-Presenter (MVP) for an architecture and in the last two years it swinged to Model-View-ViewModel (MVVM). There’s not a lot of difference between those MV* architectures, as all of them are teaching the developer to seperate the UI from the business logic(the ViewModels or the Presenters). I started implementing those architectures in my projects and started seeing how my 2000-lines of code screen classes got divided to several classes where each of them got a distinct function.

In 2018 with the Android development team at Diasyst we implemented our version of a clean approarch MVVM with a distinct seperation of the presentation, domain and data layers. I got to build the login and register feature which consists of about 25 screens and can say that the code is now very readable, testable and maintainable which were the things we were looking for.

In bigger teams that is essential as the newer developers can easily get a hold of the project just by understanding the architecture the app is written in instead of having to untangle the spaghettis.