Android Clean Code: Part 3
Learn more about the Android Clean Code mobile design pattern and unit testing your Android app piece by piece for code quality.
Having understood how to test the Android Activity and Interactor in earlier blogs of the series, let’s look at the Presenter and its testing.
What Is the Work of Presenter?
A) To change the data retrieved from Interactor according to the UI needs. Typically you may want to decorate the data or derive a value from the set of data fetched by Interactor ( For example, the total number of future trips in the list of the trips that contains both future and past trips).
B) Filter data, when needed.
C) Sort the data (default sorting), when needed.
How does Presenter communicate the created view model to Activity?
Once the view model is created, Presenter calls the Activity using the ActivityInput Interface.
Why are we using Interface?
Loose coupling - the Presenter should be testable without a real instance of Activity.
Is Android Clean Code design is influenced by unit testing concerns?
Yes, this design pattern is created with Testability as the main goal, we think if the Testability is addressed, most of the SOLID principles of software architecture will be taken care inherently.
The presenter has a class member of type ActivityInput is a WeakReference so that we don’t create circular references. These members were wired by Configurator which will be explained in a future post if you use the cleanAndroid-code-generator, these classes will be autogenerated for you.
Want to understand the presenter with real world example and code samples? Follow here