Tag Archives: library

Model View Presenter relations

Model View Presenter (MVP) in Android, Part 3

Hello! In the conclusion of the Model View Presenter in Android series, we’ll talk about:

  • How to implement MVP using the library  simple-mvp to speed up your production process
  • Common hiccups when using MVP in Android

If you missed the anterior articles, or  want to understand the Model View Presenter concept in more detail, you can read it here:

Using the simple-mvp library

The simple-mvp library was implemented using Dr. Douglas C. Schmidt concept. The code follows the canonical form principles, hence it doesn’t use any library or resource from outside the Android SDK. There are some requirements that must be followed to the framework work properly.

Attention: simple-mvp is still an experimental library created for education purposes.
Some methods and operations may change until its maturity.

Quick setup

add build.gradle compile ‘com.tinmegali.mvp:mvp:0.0.7’ Create interfaces to communicate between MVP layers
  • interface RequiredViewOps extends ActivityView
    with VIEW methods to be accessed by PRESENTER
  • interface ProvidedPresenterOps extends PresenterOps
    Operations offered to VIEW to communicate with PRESENTER
  • interface RequiredPresenterOps
    with Required PRESENTER methods available to MODEL
  • interface ProvidedModelOps extends ModelOps
    Operations offered to MODEL to communicate with PRESENTER
Implement MVP objects extending its generics MODEL from Model View Presenter (MVP) pattern.
class MODEL extends GenericModel
      implements MVP_MainActivity.ProvidedModelOps
VIEW layer of MVP pattern
class VIEW_Activity extends GenericMVPActivity<MVP_MainActivity.RequiredViewOps, MVP_MainActivity.ProvidedPresenterOps, MainPresenter>
implements MVP_MainActivity.RequiredViewOps
Could also extend GenericMVPFragment PRESENTER from Model View Presenter (MVP) Pattern.
class MainPresenter extends GenericPresenter<MVP_MainActivity.RequiredPresenterOps, MVP_MainActivity.ProvidedModelOps, MVP_MainActivity.RequiredViewOps, MainModel>

leia mais