airportmarc Posted August 9, 2011 Share Posted August 9, 2011 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. Link to comment https://forums.phpfreaks.com/topic/244362-validation-should-i-use-different-classes-for-each-rule-or-methods/ Share on other sites More sharing options...
trq Posted August 9, 2011 Share Posted August 9, 2011 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. Link to comment https://forums.phpfreaks.com/topic/244362-validation-should-i-use-different-classes-for-each-rule-or-methods/#findComment-1255087 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.