Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MVP doubts about validating

I´m starting to implement the MVP pattern on an Android project and I have some doubts about where I should validate the fields before doing any action.

For example, If I have to send a form with three fields (name, email, text). Should I validate the fields in the activity or I should send them to the Presenter for being validated?

I'm not 100% sure yet if the comunication with the presenter has to be only with the right data already validated or not.

like image 408
Jose M Lechon Avatar asked Apr 22 '16 07:04

Jose M Lechon


1 Answers

It really depends, my recommendation is that (And what I normally do):

  • If the field can be validated without access to database or complex operations, I'd do it in the activity. Examples of such fields would be: Password (Passwords need to contain at least 7 characters), Age (Age must be numeric)
  • If the field needs to be validated by accessing the database (or by web service) or the operation requires complex logic and resource, do it in the presenter. Examples of such fields would be: Username (To check if it is a duplicated username by accessing the database)

Think of it as a front-end and back-end of a website, although not completely same, it does help you to clarify confusing concepts.

like image 64
Joel Min Avatar answered Sep 26 '22 00:09

Joel Min