java - Validation Library Design Pattern selection -


i writing library used validating specific objects. implemented strategy pattern.

what best pattern implementing validation library ?

some of code shown below.

     //interface      public interface ivalidator {              public  boolean validate(object o) throws validationexception;          }       //validator object     public class validator {          private ivalidator validator;          public validator(ivalidator validator)         {             this.validator=validator;         }          public boolean validate(object o) throws validationexception         {             return this.validator.validate(o);         }      }      //email validator      public class emailvalidator implements ivalidator{          @override         public boolean validate(object o) throws validationexception {      //validate e mail here              return false;         }      }   //test run validator validator = new validator(new emailvalidator()); validator.validate("some email"); 

i guess answer question subjective can give own opinion:

i myself use strategy pattern such tasks because meant for. use specific validation strategy depending on input of function strategy pattern alright, think.

read first part of wiki article strategy pattern strategy pattern. main example validation.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -