I’m looking for any recommended validation frameworks, or patterns for an N-tier client application, I want to write the validation method once and bind it to a WPF GUI, and if possible also for server side and client side related business logic.
I’m looking for any recommended validation frameworks, or patterns for an N-tier client application,
Share
Very simple, your business entities should include a section to store Business Validation (that is business logic). This will then work whether you are designing a web based app, a client based app, a mobile app, etc. Very flexible.
Suppose you have a business object (an entity) like a customer:
You then realize that you want your business logic to state that you validate a customerID (in addition it is > 0), you require a company name (without one the customer is not valid), etc etc. These validations are your business logic layer. So you can change your customer class to inherit from say a BusinessObject layer, so your class becomes this:
You do not want objects of BusinessObject type but what businessobject serves as is an abstract class that stores validation errors and business rules. A business rule is ultimately the rules you stated when you called AddRule:
Each business rule such as validateid, validaterequired, and validatelength need to be implemented:
Those are just two samples of validatelength, and validateid, you can come up with validaterequired (check if the value exists). They both implement a business rule class:
So your businessobject class just keeps a list of required business rules and the validation errors it catches. The business rule class simply stores the property name and an error message in case a rule is not correctly applied. It also contains an abstract validate() method which is defined for each validation class. It differs for each validation class because validating an id is different then validation a required field.
The gang of four website has a lot of good help regarding this. Much of this code is taken from their models.