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.
- 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.
- 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.
- 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!