Android MVP without RxJava or Dagger
Joaquim Ley
2948

Hey Joaquim, thanks for a great read! I looked into the GitHub repo, and one thing I really like is keeping Model and Presenter layers inside a separate module: this serves as a great demonstration of the core idea of the pattern — making it possible for different frontends to reuse shared business logic. Great job!

Regarding the no-RxJava & Dagger question, I can say I’m totally with you on the former. There are tons of wonderful Android apps that don’t use RxJava, and it’s a lot better to not use RxJava at all, rather than use it incorrectly — and, as we know, the learning curve for RxJava is pretty steep. I personally think RxJava is a fantastic tool that makes solving ubiquitous Android development problems — such as networking, data caching etc. — easy and pleasant.

However, I really think that Dagger (or at least any good performant DI solution) is an indispensable framework for any serious modern Android application. As an example, here’s a code snippet from your project:

public class ListFragment {

...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
mListPresenter = new ListPresenter(DataManager.getInstance());
...
}
}

Here, ListFragment creates ListPresenter, rather than receiving an instance from the outside. Plus, that ListPresenter depends on an instance of DataManager, that would internally query data from network. Imagine you’d like to substitute real network with something like MockWebServer for Espresso tests — it’s gonna be hard with this kind of architecture, since there’s no way to properly inject a mock DataManager. With Dagger, you’d have ListPresenter injected into the ListFragment, and you can set up a test module that wires up a mock Model layer and injects it into the ListPresenter. Of course, it’s possible to get away without Dagger (e.g. DataManager.setInstance(mockInstance)), but Dagger helps abstract away all that complexity and keep your codebase clean.

Please let me know your thoughts, and I’ll be happy to continue this discussion!

Show your support

Clapping shows how much you appreciated Egor Andreevich’s story.