I recently written a ValidationBundle
, to validate the arguments passed to a method. Validation bundle accepts different types of Validator
's. Upon validating the bundle, it invokes each one of the validators registered with the bundle. I was wondering if any pre-existing design pattern is followed or not?
Well, the Builder pattern is obviously used to construct the ValidatorBundle
and the Iterator pattern is used to loop through it.
This isn't the typical Strategy implementation you would see in a tutorial, but assuming there is an abstract Validator
which is implemented by DataTypeValidator
, ArgLengthValidator
, etc., then I think it's fair to label them as "a family of interchangeable algorithms," which qualifies as the Strategy pattern.
Going beyond design patterns, it would be interesting to see this implemented with a different paradigm. Specifically, I think this type of validation could be implemented as a cross-cutting concern with AOP.