Timeline for Where to validate user input - Constructor, Validation object, or Factory method?
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 12, 2020 at 9:19 | vote | accept | CommunityBot | ||
| Jun 12, 2020 at 8:57 | answer | added | Flater | timeline score: 3 | |
| Jun 12, 2020 at 8:47 | comment | added | anon |
That helps insofar as it makes it clear that (assuming MVC) the validation should be in the model, which I suppose means the controller shouldn't guard too much (e.g. let Comments.Post(...) fail rather than having if User.CanPost(..) { Comments.Post(..) }, but I'm not sure it solves my underlying question. I think part of what I'm stuck on is if you have User.Create(...) throw an exception when passed bad data in multiple fields, how do you extract just the problematic fields to display to the user? I think that's what my Validation class was born of.
|
|
| Jun 12, 2020 at 8:28 | comment | added | Christophe | To come back to the bank example: credit card number verification is one kind (input control of the number format, not trusting UI).The. he k if the number is valid (checksum control) is another one. The check if credit card is stolen is another kind of verification (business logic). As it’s validation for different purposes, the answer may be different. Anyway, does this help: stackoverflow.com/q/57603422/3723423 ? | |
| Jun 12, 2020 at 8:13 | comment | added | Christophe | On contrary, I find this question very interesting! I even upvoted (there will always be some folks who downvote questions, don’t worry about that). | |
| Jun 12, 2020 at 6:58 | comment | added | anon | I'm not even sure the question makes sense anymore. Usually when it takes this much explaining, it means I've "architecture astronauted" myself well past an obvious answer. I always get like this on personal projects, because I get obsessed with doing things The Right Way at all costs. | |
| Jun 12, 2020 at 6:56 | comment | added | anon | I think this is a pretty noob question, but unfortunately the system won't let me delete it now. As a generic example, think of a banking app that has multiple places it would take in a card number, account number, PIN, amount. If I have a transfers controller with three actions to send to email/external account/internal account, I want to validate the user input before sending it to the models responsible for setting up the transfer so I don't have conflicting validations between them. This leads to the three possible scenarios above, each seeming to have issues. | |
| Jun 12, 2020 at 6:38 | comment | added | Christophe | Could you clarify the architectural model of your system? and the kind of validation you're doing (user input validation? object invariants and consistency or business rules)? And perhaps as well if your domain objects are anaemic or plain? | |
| Jun 12, 2020 at 5:33 | answer | added | candied_orange | timeline score: 0 | |
| Jun 12, 2020 at 5:33 | answer | added | wasatz | timeline score: -2 | |
| Jun 12, 2020 at 4:13 | history | asked | anon | CC BY-SA 4.0 |