none
How do i design Validator? RRS feed

  • Question

  • Hello all,

    How do i design data and business rule validator?

    You can assume having a customer with say some of it's properties being validated and an order having a business rule say - an order cannot be placed unless total amount is greater than 10$.

    Thanks,

    Monday, September 26, 2011 12:31 AM

All replies

  • Hi,

    This Business specific validatation and rules can be implemented in the Business logic layer.

    For example, you have customer related data in the database, using the DAL the customer realted information will be retrived and customer object will be created. This customer object should have the properity for holding the business rule related values.

    This customer object will be passed to the Business logic layer, In the business logic layer the validation will be carried out.

    Hope you quesiton is answered,

    Regards

     

    Monday, September 26, 2011 3:05 AM
  • One option is to create an interface, named IValidatible and declare a method in that interface named Valid that returns a bool. You can then have your business class, Customer, implement this interface. You place all of the validations inside the Customer's Validate() methodSomething along the lines of:
    public interface IValidatible
    {
        bool Validate();
    }
    
    public class Customer: IValidatible
    {
        public int Amount;
    
        public bool Validate()
       {
           if (this.Amount < 10)
               return false;
       }
    }
    Hope this helps

    Paul Delcogliano
    Saturday, October 22, 2011 2:52 AM