Search code examples
androidkotlinmvp

In Android MVP, should a presenter return a value?


I try to learn MVP, I have some question to ask, should a presenter return a value?

something like this:

class MainPresenter : BasePresenter<MainContract.View>(), MainContract.Actions {
    override fun getProducts (id: Int): List<Product> {
        //...
        return products
    }
}

interface MainContract {
    interface Actions {
        fun getProducts(id: Int): List<Product>
    }
}

or like this:

class MainPresenter : BasePresenter<MainContract.View>(), MainContract.Actions {
    override fun getProducts (id: Int) {
        //...
        mvpView?.showProducts(products)
    }
}

interface MainContract {
    interface Actions {
        fun getProducts(id: Int)
    }

    interface View{
        fun showProducts(products: List<Product>)
    }
}

Solution

  • The first question we ask is, to whom should presenter return value? Who is interested in presenter values? Do we want to mess our business logic with view layer? Given that our business logic is inside the presenter itself, who else is interested in any data?

    Definitely that's not our intention and diverts from MVP. We need to propagate the values through interfaces, usually View layer methods and pass them as arguments to other interested parties that reside in the view layer.