Adding Validation rules to the View in MVP
Hi, I am working on a MVP windows forms application and I would like to know if it would be right to put data validation in the view and in the model ? The example in the Patterns In Action only uses the Model for validation.
Thanks in advance.
Heleno Sales Mesquita, Oct 10, 2013
In general you always want to reduce code duplication as much as possible.
Having said this, Validation is an area where this is almost impossible. The reason is that to get the best user experience requires that validation takes place in the UI (Presentation layer) in addition to the Business Object and Data Access layers.
In a Windows app it is usually easier to share Validation code because it is all written in .NET.
So, the short answer is, yes, you can add Validation in the View in addition to the Model, but see if there is a way to share (i.e. refactor) the validation rules.
Hope this helps.
Jack Poorte, Oct 11, 2013