Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:24:25+00:00 2026-05-26T19:24:25+00:00

We have a set of about two dozen classes that inherit from a base

  • 0

We have a set of about two dozen classes that inherit from a base class which has an abstract Validate method. Of course each class has different validation needs but the rules are needed in different combinations between all of them so, as you can imagine, this resulted in a lot of code duplication, as an example:

Class A needs rules 1, 3, 6, and 9
Class B needs rules 3, 4, and 8
Class C needs rules 1, 8, and 9
….

you get the picture.

So I was thinking of doing a simple refactoring and create a Validation Decorator in which each rule would be encapsulated in a class and a factory that would create the adhoc validation combination for each class.

Then I started thinking that each rule is so simple that instead of creating all the plumbing for the decorator I could probably just have Action delegates stored in the factory which would populate a List(Action(T)) so that each class would just iterate through that list executing each delegate.

The problem is that the number and/or types of parameters vary between each rule, as an example:

Rule 1 needs a nullable DateTime, a DateTime, and an enum.
Rule 2 needs a nullable DateTime, and a DateTime.
Rule 3 needs a string …..

Is this something that can be accomplished or have I not choice but to code the Decorator?

Thanks for your thoughts and ideas.

UPDATE:
Some rule examples:

if(EndTime.HasValue && StartTime > EndTime)  
     Throw new Exception (...);

if(Status == StatusEnum.Pass && !EndTime.HasValue)  
     Throw new Exception (...);

if(string.IsNullOrEmpty(ProcessName))
     Throw new Exception (...);

if(string.IsNullOrEmpty(ProductName))
   Throw new Exception (...);

if(string.IsNullOrEmpty(CustomerName))
   Throw new Exception (...);

All the involved classes have the properties DateTime? EndTime, DateTime StartTime, StatusEnum Status, and string ProcessName.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:24:25+00:00Added an answer on May 26, 2026 at 7:24 pm

    Why not make an interface called something like IValidationParameter Then have each validation rule have an implementation of IValidationParameter. For example

    public class Rule1ValidationParameter : IValidationParameter
    {
        public DateTime? FirstDate { get; set; }
        public DateTime SecondDate { get; set; }
        pulbic MyEnum MyEnum { get; set; }
    }
    

    Then make your list List<Action<IValidationParameter>>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c# class that has 20+ string properties. I set about a
I have a question about how to set up the relations between two models
I have a set of X,Y data points (about 10k) that are easy to
I have a PHP-generated page which is displaying some data about a set of
I have a Silverlight application which loads about 2000 objects of half a dozen
I have a question about a class which implements both mouseListener and mouseMotionListener in
I have two entities: match and player , which I have set up with
I have experienced about two times that mysql database crashes and it can not
I have a large set of words (about 10,000) and I need to find
I have to set GridView.DataKeyNames (This is really a question about the syntax for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.