Do I need to create interfaces for my Presenters?

Mateusz Herych
Jul 8, 2016 · 1 min read

MVP is no longer a hot topic in Android development. It became a standard. At IG, we implemented it to put our Fragments and Activities on a diet and to make the whole codebase better structured and more testable.

Today I found this article while scrolling my Twitter feed. I like it a lot and I agree with Pedro’s points. Find below a couple of additional arguments for which you shouldn’t really create interfaces for your presenters.

  1. Some commenters disagree with the author, claiming that interfaces make it easier to test your code, because they let you easily mock your presenters in unit tests. This is only partially true. While interfaces definitely won’t make it harder, you can easily stub concrete classes with probably any mocking framework available nowadays. The most popular one, Mockito, lets you do that with no hassle.
  2. If you’re using Dagger (either 1 or 2) which — if you implemented MVP already — is often a case, referencing your Presenters via interfaces will cost you additional effort to map your interfaces to concrete implementations in your graph. Skipping interfaces will let you inject presenters to views with a simple, test-friendly, constructor injection.
  3. I think it’s very unlikely that you’ll ever need more than one implementation of a single Presenter interface. And even if you’ll need to do that, you can extract an interface out of concrete class in no time using your IDE.

What’s your opinion? Are you extracting interfaces for presenters? I’m looking forward to your comments!

Mateusz Herych

Written by

Android Tech Lead at @IGCom, Google Developer Expert for Android.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade