Re: Where to put routine to perform data validation and read from/write to database in MVC designed user interface ?
Wednesday, April 2, 2003 02:24 PM
If you are actually following the M-V-C model, you already know the answer.
M = model, or the busines logic and processing rules.
V = view, the user interface portion.
C = controller, the systems processing controlling the app.
Data validation has at least two levels.
The first level is usuall field level. When a user enters data, there should be some level of user input validation in the user interface. For example, when entering a five digit zip code, the UI would ensure the entry was all numeric and of length five. This is field level validation which is independent of any other fields entered. What the UI would NOT do in most cases is verify the zip code is an actual zip code and valid for a given address.
A second level of checking is ensuring data consistency and possibly data validation. Data consistency is often in the context of other data entered on a form or screen, such as ensuring a zip code is valid for a given address and ensuring a given address is an address recognized by the postal service. Such validation rules can be quite complex and are usually driven by business rules. These (business) rules are in the Model portion of the MVC approach.