CLEAN-5: Keep the UI thread as lightweight and isolated as possible.


Description

In accordance to guidelines CLEAN-1 and CLEAN-2, presenters residing in the outer layers of apps modeled through clean architecture principles should be kept lightweight. In fact, Presenters should be composed with interactor components, i.e., use cases residing in the business logic layers, which are responsible for executing tasks outside the main UI thread of the app. Once the task are finished, the Views are updated through a callback with the processed data. Besides callback-based communication among components, other techniques used in order to keep the UI thread lightweight rely on the inversion of control principle and intent-based communication.

Example

We created a simple MVP login Application. The event diagram of the MVP login:

Each presenter in our MVP Login example contains an interactor. And performs the job in a new thread, and comes back using a callback.

Login Injection

This keeps the UI thread lighter than when the MainActivity would perform the request on the MainThread.

Check out the Github page to view the complete repository.