only responsibilities are to set up/update the UI and handle user events. Therefore, they become easier to maintain. • We can now easily write unit tests for the presenters by mocking the view layer. Before, this code was part of the view layer so we couldn’t unit test it. The whole architecture becomes very test-friendly. • If the data manager is becoming bloated, we can mitigate this problem by moving some code to the presenters.
for the results of the events, we provide a clear sequence of reactions to the events that are going to happen. - Observable - Observer - Subscriber - Subscriptions - Subjects
for having nested callbacks. • The interactors (DataManager) takes over responsibilities that were previously part of the view layer. Hence, it makes Activities and Fragments more lightweight. • Moving code from Activities and Fragments to the DataManager and helpers means that writing unit tests becomes easier. • Clear separation of responsibilities. Helper classes or the interactors (DataManager) can be easily mocked.
.subscribe(response -> { if (response.isEmpty()) { getMvpView().showMoviesEmpty(); } else { getMvpView().showMovies(response); } }, throwable -> { Timber.e(throwable, "There was an error loading the movies."); getMvpView().showError(); })); } Result over main thread Process over other thread Any error Response loadMovies() method in MainPresenter.java
dependency graph is created for us, we can easily swap out modules that make network responses and mock out this behavior. • Since dependencies can be injected and configured externally we can reuse those components. • We can just change the implementation of any object without having to make a lot of changes in our codebase, since that object instantiation resides in one place isolated and decoupled.
https://goo.gl/U8M8B9 • Dependency Injection with Dagger 2 by Jake Wharton: https://goo.gl/pweC7P • Grokking RxJava, Part 1: The Basics by Dan Lew: http://goo.gl/60AYDU • Android Application Architecture by Iván Carballo: https://goo.gl/6xX2oW