在MVP中写验证的位置 [英] In MVP where to write validations

查看:99
本文介绍了在MVP中写验证的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Model-View-Presenter模式下,我们应该在其中编写用户输入的验证.

In Model-View-Presenter pattern where should we write validations of user input.

推荐答案

特定于域的规则/验证应在模型中.您可以使用model.validate()来通知您是否违反规则.查看Rails模型(ActiveRecord)类,以很好地实现此概念.

Domain specific rules/validations should be in the Model. You can have a model.validate() to let you know if the rules are not violated. Look at Rails model (ActiveRecord) classes for a good implementation of this concept.

视图应使用户难以键入无效的输入.因此,在到达演示者之前,应先消除为数字输入字符串"类的输入错误. 模型和视图之间可能会有一些重复的验证.例如. AttributeX的范围必须在1到100之间.必须在模型中对此进行验证..同时,您可能希望在minValue和maxValue范围设置为1-100的情况下在UI中放入微调器.

The View should make it difficult for the user to key in invalid input. So 'entering a string for a numeric value' class of input errors should be nipped before reaching the presenter. There may be some duplication of validations between model and view. E.g. AttributeX must range between 1-100. This must be validated in the model.. at the same time you may want to slot in a spinner in the UI with the minValue and maxValue range set to 1-100.

这篇关于在MVP中写验证的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆