[bv-dev] Hosting of method validation methods

Gunnar Morling gunnar at hibernate.org
Tue Jul 24 18:00:58 EDT 2012


Hi,

2012/7/23 Hardy Ferentschik <hardy at hibernate.org>:
> Hi all,
>
> Let me pick up yet another TODO from the current spec.
>
> Section "5.1.2. Method-level validation methods" [1] still contains a TODO whether the methods for method validation should be hosted
> on a different interface (other than javax.validation.Validator).
>
> At the moment all validation methods are hosted on javax.validation.Validator. Personally I don't see a strong reason for introducing
> another indirection/interface. Does anyone have objections removing the todo?

I guess Emmanuel does :)

Personally, I also used to be of the opinion that a separate interface
doesn't really add much value. What made me pondering though was the
recent discussion about adding new bean validation methods such as
validateProperty(T object, Path property, Class<?>... groups);

Following the interface segregation principle [1], it may indeed be a
good idea to have two separate interfaces, one for standard bean
validation and one for method validation. I think the main question
is, who the consumers of the individual methods are. I think there may
be a broader range of users of the bean validation methods
(validate(), validateProperty() etc.) than of the method validation
methods (validateParameters() etc.), which typically will only be
invoked by authors of integration/glue code. So for users of the first
group it would reduce complexity if the method validation stuff went
into a separate interface.

With respect to retrieving method validators, instead of something
like Validator#forMethod(Method method) etc. I could also imagine
ValidatorFactory#getMethodValidator(). Then one doesn't have to
retrieve a new validator for each validated method/constructor.

--Gunnar

[1] http://en.wikipedia.org/wiki/Interface_segregation_principle


>
> --Hardy
>
> [1] http://beanvalidation.org/1.1/spec/#d0e3831
> _______________________________________________
> beanvalidation-dev mailing list
> beanvalidation-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/beanvalidation-dev


More information about the beanvalidation-dev mailing list