Search code examples
androiddesign-patternsmvpandroid-mvp

Android MVP: login credential validation


I started learning MVP in the last couple of days and I found this interesting tutorial. I followed the code step by step to implement login functionality in my app. However, I still have difficulties understanding where the input validation should be! In the tutorial inside the LoginInteractorImpl class inside the login method (2 functionalities in one method!). My questions is, why would I have to reach the Interactor class to validate the credentials? Why not validating the input in the Presenter class and if the input is correct I pass it to the Interactor?


Solution

  • The presenter is the glue between your views and your models all it does is exchange the information between the two. It shouldn't be doing any kind of logic, only it's designated task. Read about Seperation of Concerns.

    What would happen if you need to implement another login screen and you want to use the same logic from your LoginInteractor? You'd have to add validation logic to your new presenter. Or what if you change your validation technique?

    Changing the logic should not have an effect on the presenter, and vice-versa. The presenter is only concerned with passing information.