How would you structure your code in the following scenario:
Several business objects (e.g.Person, House, etc), and between them, you need to validate the user inputs (which come in from textboxes). Would that go in either:
Thanks
A very widely used approach, which I endorse in such scenarios, is to introduce the concept of a viewmodel: a class that aggregates all data to be displayed in a form, and which specifies (through attributes or some other mechanism) what type of validation should be performed on this data.
This approach has several benefits which include:
The actual code that does the validation will typically be inside a separate validation class; your viewmodel would only dictate how each piece of validation should apply to each piece of data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With