I was doing R&D on MVP and I am thinking to use this design pattern for my next project. But I am facing a problem with this design pattern.
Please have a look at below java code.
I have a BaseActivity class
public class BaseActivity extends AppCompatActivity {
}
An Interface BaseView
public interface BaseView {
void showLoader();
void hideLoader();
}
One more interface which extends BaseView Interface to maintain relation between views
//Game start from here
public interface TestView extends BaseView {
void showResult();
}
Here is the final Activity :
public class MyTestActivity extends BaseActivity implements TestView {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_test);
}
@Override
public void showLoader() {
}
@Override
public void hideLoader() {
}
@Override
public void showResult() {
}
}
2 methods showLoader() and HideLoader() from BaseView are common to every interface which extends BaseView. that's why I keep them into BaseView. no problem till now.
Problem is: I have to implements and provider definition of these methods in every class which implements BaseView or its Child interface.
Example: Here in
TestActivity extends BaseActivity implements TestView
So to prevent this problem I implemented BaseView into BaseActivity and provider these methods definition. But I can see BaseView is coming to TestActivity from BaseActivity(if I implement BaseView in BaseActivity)
And Also from TestView which is already implementing BaseView. It's my requirement TestView must extend BaseView. if i do not implements BaseView in BaseActivity i need to implements showLoader() and hideLoader() methods in every Activity class. right now I have 2 methods in BaseView they can be more...
Please suggest any solution.