Does anyone have the history on why Validateable &...
# questions
j
Does anyone have the history on why Validateable & GormValidateable don't have a common interface between them?
j
I think so. I am in meeting away from keyboard. Will respond later.
❤️ 1
I looked at the history to refresh my memory and now I am not sure. I know that the validation process for an entity is different than the validation process for any other Validateable and much of the Entity specific stuff is in GormValidationApi. GormValidateable delegates to that for the real validation work. What I don't recall is why we didn't allow for more reuse across those. I think they probably could have a common interface between them. I am sorry that isn't much help.
j
Thank you.
m
FWIW, I would prefer it to be split. Constraints mapping for GORM involves setting up entities vs constraints mapping on plain Validateable used for forms. For instance, “nullable”/“unique” for GORM sets up nullness/unique keys of a table column, while on plain form validation it only checks the value when you call validate. These are clearly two different behaviours.
IIRC, the split was done around the time when GORM was being made to be able to be used standalone without Grails. I don’t know the exact reason but I think maybe it didn’t make sense for standalone GORM to also carry all of the web validation and type converter bits that were previously coupled together?
👍 1
j
I was thinking something more simple then that - just a common interface without having to bring along all of the dependencies.
that way if you want to take something that can validate, you can use that interface instead of just def
m
Sounds like it would easily lead to a diamond problem, with Grails domain object binding on controllers.
j
What's odd is there's already shared methods between them: • getErrors() • hasErrors() • validate() So that's really all I woudl propose. No additional dependencies, and a common base so if you wanted to write code that takes either a gorm validateable or a validateable you could.
👍 2
you think that would still be a diamond ?
m
I see, so it would just be a duck-type interface?
j
Exactly
it's better than def or Object everywhere
m
I don’t think it’s that big of a deal to be honest. Two of the methods are just getters to a Spring Errors object, so why not just use Errors in your methods. As for validate(), I think of Validateable and GormValidateable have very different execution contexts. If you have one interface, how do I know which one is it?
j
In my particular case, it's an generic uploader function. You can create domains or commands (and the caller can do whatever it wants with the commands). The duck typing would just allow me to remove Object everywhere.
m
FWIW, I am guilty of writing my own wrapper trait over Validateable to: 1. allow merging errors from e.g. a GormValidateable domain object. 2. Extract errors from within lists, since they aren’t Validateable themselves. So I understand the need.