[coldbox:4855] Helpers and models

Just my opinion, but to me, validation is as much a part of my app’s business logic as any other part; therefore, I do believe that I would move validation into its own model object.

Hi Doug, thanks for answering! I was thinking about it too, in moving some things to its own model, but then I have just ONE form validation in the entire app, so maybe creating a model just to do it will be too much…

Thanks again,

Fernando S. Trevisan (Programador)

Also, don't necessarily assume that "validation" is a single concern. Conceptually, comparing password to confirmPassword fields is a controller concern whereas ensuring that a required firstName has been entered (to describe a valid user) may well be a model concern. In practice, the details of your application will drive how you handle this (you may put all validation in either controller or model for simple apps) but it is worth starting to consider that validation isn't necessarily a single concern.

Best Wishes,

well, the beauty of using frameworks and patterns is to be ready when changes do occur; it’s almost a certainty that at some point you’ll be either adding additional validation or having to change existing validation, so in my opinion taking the time to create a model validator would not be a waste of time at all; it’ll leave your app prepared to evolve. :slight_smile: For instance, what if, at some point, you expose your model as a web service, and the data being submitted VIA webservice calls needs to be validated? The perfect place for that validation to be at that point is in the model, right?

I agree with Doug in some ways, but just to play devils advocate, there is also something to doing “the simplest thing that will work”. It isn’t an excuse for cowboy coding or bad architecture - it is just saying “right now I don’t have multiple UI’s, so I’m gonna put the validation in a controller function, nicely encapsulated, and I know just how I’ll refactor it if I do need another UI down the line”.

However, it’s a trade off. You don’t want to create oodles of validation in the controller that’s gonna be a PiTA to refactor if you know you’re gonna need a restful web service interface next month. Also you have to have the discipline and management support to do the refactoring properly when it is required. A good set of regression tests is also a pre-requisite for the “keep it simple and refactor” approach.

Neither approach is “right”. Both are worth considering.

Best Wishes,