Given:

Activation that implements n interfaces. References to them are passed to another class (the ViewPager ViewPager handler, for example), through the constructor arguments.

Idea:

Instead of transmitting a set of different types of arguments, only one type is sent - activation type, the interface implements, in the name of reducing the number of arguments with further casting the activation link to the type of necessary interfaces.

Doubts:

Something somewhere once read about memory leaks when using links to activate. On the other hand, the links to the implemented activation interface are the same, right?

Question:

Is it worth it to give the class references to the interfaces implemented in the activity by referring to Activity , and not to interfaces?

    1 answer 1

    It is better to pass a class that implements the interface as an interface — this is correct from the ООП point of view.
    When you pass an activation that implements an interface, for example ClickListener , to an instance of the View class, then you transfer activations there, and all memory leaks associated with this will be present. And it does not matter which type is specified in the parameters of the method being accepted.
    To avoid leaks, you need to reset the listener to onPause() , and resume to onResume() .

    • In short, your idea smacks of crutches - andreich
    • Those. if I ClickListener to the ViewPagerAdapter , then I also need to ViewPagerAdapter setter to the ClickListener so that they can reset the links to onPause and then assign them back to onResume ? And so it will be right and no leaks? - Yuriy SPb
    • 2
      @YuriSPb so recommend. Yes, there should be no leaks because of this. there is an alternative. It is possible to do separate classes by the Lasens that do not refer to activation, and in them they can use evenbus github.com/greenrobot/EventBus or otto square.imtqy.com/otto If used correctly, there will be a profit and no leaks. - andreich