Android fragments are often thought of as Views in MVP or MVC patterns, they should not contain any application logic within. All meaningful events from the fragment should be delegated to presenters which are often implemented via Activity
.
Suppose you have a fragment A
and a fragment B
. Fragment A
displays a list of items and fragment B
displays details for the selected item. If you communicated fragments directly it would create a tight coupling between them since fragment A
would need a concrete fragment B
reference in order to instantiate it. If your application requirements change, for instance by showing fragment C
instead of B
, the tight coupling will pop out and you would have to deal with it. You can avoid this coupling by introducing a Presenter
or Controller
interface into your fragment. By calling this interface methods you can be sure that the implementation of your presenter logic is decoupled from fragment appearance logic.
For more information about developing decoupled application architecture check out this article http://fernandocejas.com/2014/09/03/architecting-android-the-clean-way/