3

Should a validator change his object during validation?

I want to validate the address of a person with Google geolocation api. That needs one request against their api. After then I would need the lat lng in the person object. So I would need to request again. So should the validator update the object directly when it got checked? Or is there a better solution?

Comments
  • 1
    Interesting Question.
    Basically I would say that a validator, because of its name, should only do the job of validation and therefore not change the object.
    I think it's not best practice if you manipulate an object during validation.

    As a solution to your problem, depending on your development stack, you could fetch the location data during/after user input (e.g. a custom address field input component) and later validate the data, including location, with your validator.
  • 0
    I decided to use a cache in front of location method... address doesn't change often 😑
Add Comment