Search code examples
androidandroid-mvp

Why do we use Base View and Base Presenter for MVP pattern?


in MVP (Model View Presenter) pattern using base view and presenter is common practice. Can we omit them? and why do we use it at the first place?


Solution

  • The reason behind using BaseView and BasePresenter is to move common methods across child to parent, for suppose most of your views have showProgress() method , you can stop declaring it in each child and move to parent as in

    interface BaseView{
      void showProgress();
    }
    
    interface SomeView extends BaseView{
      void someAction();
    }
    
    interface OtherView extends BaseView{
      void otherAction();
    }
    
    interface NoProgressView { // this view doesn't need progress so avoid extedning
      void dummyAction();
    }