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 494873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:32:23+00:00 2026-05-13T05:32:23+00:00

I’m not sure if there is a pattern that should be used here but

  • 0

I’m not sure if there is a pattern that should be used here but here is the situation:

I have a number of concrete classes that implement an interface:

public interface IPerformAction
{
   bool ShouldPerformAction();
   void PerformAction();
}

I have another class that checks input to determine if ShouldPerformAction should be execute. The rub is that new checks are added fairly frequently. The interface for the checking class is defined as follows:

public interface IShouldPerformActionChecker
{
   bool CheckA(string a);
   bool CheckB(string b);
   bool CheckC(int c);
   // etc...
}

Finally I currently have the concrete classes call each of the checker methods with the data specific to that concrete class:

public class ConcreteClass : IPerformAction
{
   public IShouldPerformActionCheck ShouldPerformActionChecker { get; set; }

   public string Property1 { get; set; }
   public string Property2 { get; set; }
   public int Property3 { get; set; }

   public bool ShouldPerformAction()
   {
      return 
         ShouldPerformActionChecker.CheckA(this.Property1) ||
         ShouldPerformActionChecker.CheckB(this.Property2) ||
         ShouldPerformActionChecker.CheckC(this.Property3);
   }

   public void PerformAction()
   {
      // do something class specific
   }
}

Now each time I add a new check, I have to refactor the concrete classes to include the new check. Each concrete class passes different properties to the checking method so subclasses the concrete classes is not an option. Any ideas on how this could be implemented in a cleaner manner?

  • 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-13T05:32:23+00:00Added an answer on May 13, 2026 at 5:32 am

    The “CheckA”, “CheckB”, etc. names, presumably chosen to avoid exposing confidential information, also obfuscate the nature of the relationships between classes, so I’ll have to wing it.

    However, this is very nearly double dispatch, except you are performing conversion of the objects in-between.

    EDIT: Try playing the double dispatch pattern “by the book”, rather than decomposing the objects mid-dispatch. To do this, you’d need something like the following:

    public interface IPerformAction
    {
        bool ShouldPerformAction(IShouldPerformActionChecker checker);
        void PerformAction();
    }
    
    public interface IShouldPerformActionChecker
    {
        bool CheckShouldPerformAction(FloorWax toCheck);
        bool CheckShouldPerformAction(DessertTopping toCheck);
        // etc...
    }
    
    public class FloorWax : IPerformAction
    {
        public string Fragrance { get; set; }
    
        // Note that the text of this method is identical in each concrete class,
        // but compiles to call a different overload of CheckShouldPerformAction.
        public bool ShouldPerformAction(IShouldPerformActionChecker checker)
        {
            return checker.CheckShouldPerformAction(this);
        }
    }
    
    public class DessertTopping: IPerformAction
    {
        public string Flavor { get; set; }
    
        // Note that the text of this method is identical in each concrete class,
        // but compiles to call a different overload of CheckShouldPerformAction.
        public bool ShouldPerformAction(IShouldPerformActionChecker checker)
        {
            return checker.CheckShouldPerformAction(this);
        }
    }
    
    public class ShimmerApplicationChecker : IShouldPerformActionChecker
    {
        // handles binding of FloorWax class to required checks
        public bool CheckShouldPerformAction(FloorWax toCheck)
        {
            return CheckAroma(toCheck.Fragrance);
        }
    
        // handles binding of DessertTopping class to required checks
        public bool CheckShouldPerformAction(DessertTopping toCheck);
        {
            return CheckAroma(toCheck.Flavor);
        }
    
        // some concrete check
        private bool CheckAroma(string aroma)
        {
            return aroma.Contains("chocolate");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I need a function that will clean a strings' special characters. I do NOT
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

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.