OOP General Question with C# and ASP.NET

Hey all,

I have a general question about a C# class that’s backing up my .NET app.

I’m sure it’s a common scenario – I’m creating validators for various types of objects so I can test to ensure all business rule requirements are met. I wanted to do it this was so I could use injection of various objects to test, etc.

All my validators will use the same base class – let’s call it myValidator<T>. from this, I’d like to derive categoryValidator : myValidator<CategoryObject>, that tests CategoryObjects, etc.

the validator object will have a check() method, a returnobject() method, etc. the check() method will check conditions of the object and will add broken business rules to a list of any conditions are violated.

So, in essence, the methods are all the same, except the method that changes business rules.

I’d like to inherit all the other methods of validator<T> , but make it so that each class has to define its own CheckBusinessRules() method.

Is there a way that I can require an override of the CheckBusinessRules() method while inheriting all the other methods of the validator<T> class?

I’d be happy to provide more information or detail if it helps.

Thanks in advance for any help you can give! :smiley:

All the best,
Sean

Good suggestions all around.

@wwb_99, I absolutely love the idea and ease of FluentValidation – I’ll check it out today! Thanks for the tip. :slight_smile:

I’d also check out alot of the validation frameworks that really do this for you. Stuff like FluentValidation or DataAnnotations . . .

you declare both the base class and the CheckBusinessRules mehtod as abstract.