0

I need to sort the list using Comparator which depends on Resources. The list (data) is loaded from the repository (Model layer). How can I do this if a Presenter should not have access to Context? Should I inject already created Comparator?

new ProductsPresenter(new ProductsRepository(), productsFragment, new ProductsComparator(context))

(prodcutsFragment is a View layer)

  1. Is it correct?
  2. What if the Presenter needs to use more Context depended classes? If I inject all of them, the constructor will have a lot of parameters.

Here is the code from Android blueprints where for example I'd like to add sorting the list with Comparator depended on Resources.

AppiDevo
  • 3,195
  • 3
  • 33
  • 51

1 Answers1

0

1 - It's correct. An improvement would be to use some kind of dependency library, like Dagger, to inject the instances directly, so you don't have to write new in constructor

2 - IMHO the best way is to inyect classes directly, without Context, to make your Presenter decoupled of Android SDK, so you'll be able to test it more easily

Daniel Luque
  • 116
  • 1
  • 8