Jump to content

Validation. Should I use different classes for each rule, or methods?


airportmarc

Recommended Posts

Hello all,

 

This is more a design question.  I am rebuilding my validation class, and have looked at a few different frameworks to see how they do it.  What I see is that they create a base class, then each validation method extends this.  eg. Required is a Class that extends Validate.  Is there a benefit to doing this, compared to have a single class with a required method?

 

Any insight would be great.

 

 

 

 

It does mean that you have a standard interface. With all validations being done via the same method. This way you can do things such as:

 

$validators = Validator::get();
foreach ($validators as $validator) {
  $str = $validator->validate($str);
}

 

Doing it with a separate method for each you would need to know all the different method names at runtime.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.