1

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.

asked Feb 12, 2018 at 16:27
3
  • Possible duplicate of Style for control flow with validation checks Commented Feb 12, 2018 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. Commented Feb 12, 2018 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. Commented Feb 12, 2018 at 16:57

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.