M
Miguel De Anda
I have a set of classes that I will be using for validation of user input. I
was previously using a class loader to load what class I wanted to use for
validation but I ran into a few problems when switching over to tomcat. This
made me wonder if my solution was good or not.
I've made each of my validation classes implement a common interface and it
only needs to have one method:
Object validate(Object value, Object[] params);
Where the params array is a simple way to allow any number of parameters as
options to the validation function.
I initially chose a classloader because I figured it would allow any number
of validation classes without any problems at compile time. It would also be
easy since adding a validation to something would be as easy as telling the
object the validation's name, and parameters. As I was looking at the
problem I got with tomcat (file not found), I starting thinking that using
Class.newInstance might work just as well. Are there any benefits to one
over the other?
was previously using a class loader to load what class I wanted to use for
validation but I ran into a few problems when switching over to tomcat. This
made me wonder if my solution was good or not.
I've made each of my validation classes implement a common interface and it
only needs to have one method:
Object validate(Object value, Object[] params);
Where the params array is a simple way to allow any number of parameters as
options to the validation function.
I initially chose a classloader because I figured it would allow any number
of validation classes without any problems at compile time. It would also be
easy since adding a validation to something would be as easy as telling the
object the validation's name, and parameters. As I was looking at the
problem I got with tomcat (file not found), I starting thinking that using
Class.newInstance might work just as well. Are there any benefits to one
over the other?