Two months passed, I worked with MVP Structure to create Android applications.
As explained in every link I found regarding MVP, the Presenter class takes care of all business logins and data (from the Model class), I realized this and started working.
One of the advantages shown in the tutorials, I want to emphasize here that MVP simplifies unit testing, because there is no dependency on the views (Fine, I also understood this).
What I did not understand is why I need to make an interface for updating views from the host, whereas I can just call the host method, which will return a value, and I can set it there?
Let's take advantage of what I said above (Unit testing). Using these interface modules will be more problematic, since the method will require the implementation of an interface to complete an operation that we do not have in unit testing (I know that the Instrumental test is also part of the unit test, but they are only told about non-ui testing).
I just prefer to call the presenter method and get the value and set it in the fragment itself or in the action itself, where when creating the interface creates another level of complexity and an unnecessary declaration of the interface, all the presentation operations should be implemented. This is a kind of disappointment.
, , -, . , . . . - .
class Presenter
{
private ViewInterface viewInterface;
public void setViewInterface(ViewInterface viewInterface)
{
this.viewInterface = viewInterface;
}
public void calculate()
{
viewInterface.updateView();
}
}
class Presenter
{
public int calculate()
{
int result = -1;
return result;
}
}
,
class MyFragment extends Fragment{
....
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.layout1, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState)
{
super.onViewCreated(view, savedInstanceState);
int result = new Presenter().calculate();
}
}
, .
.
.