The task is to design a generic validation tool . It should be
- able to validate n different type of entities.
- Each entity has its own set of validation constraints.
- each Entity can be composed of zero or more other entities
- The validation operation will validate n or less than n entities every time, each validation will return a Validation result containing details of failure (if any),The final response should be a combined result of all the validations
- The sequence of validations might differ.
- The entity classes are already existing and cant be modified.
Is visitor design pattern a good choice here? I will have to create classes corresponding to each entity which will have "has-a" relationship with each entity and this class implements an interface with accept method. Is this too much convoluted logic?
I am using Java 8 , so is function composition a good choice here. Another option is having a Collection of validate functions for each entity and then composing them on the fly , and using it. Is this the right direction? Any other options that you guys can point me to?
Aucun commentaire:
Enregistrer un commentaire