I'm writing this in node.js

I have some data that needs validating before anything can be done with this. The data is validated in two different ways. I can use JSONSchema to validate the structure of the data e.g. the data must contain a name property of minLength 1 and maxLength 100. I then use another validator for business rules e.g. if (x and !y) { throw error).

Both with the structural validator and the business logic validator, i'm looking at somewhere around 40 odd rules to validate against. Current thinking was to use the Visitor design pattern (as shown in this question Design Pattern for Data Validation), however, I might be over thinking this, But i was wondering if having 2 validation classes (structural and logical) with over 20 rule validations (in each class) and various other helper functions is too large... part of me is wondering if really each rule (and it's helpers) should be broken out into it's own class... then use the pipeline pattern? or something else entirely.

  • Possible duplicate of Style for control flow with validation checks – gnat Feb 12 '18 at 16:37
  • 2
    Putting each validation rule into its own class is surely worth to consider. But without actually seeing your code and the way the rules are applied to the data, it is nearly impossible to give you a sensible recommendation. For reviewing your code, however, codereview.stackexchange.com might be the better place. – Doc Brown Feb 12 '18 at 16:40
  • not sure it is a duplicate @gnat, it might be better places on the codereview stackexchange as Doc Brown has suggested, though i'm still very early with the code. – Jarede Feb 12 '18 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.