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

  • Home
  • SEARCH
  • 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 6574553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:16:33+00:00 2026-05-25T15:16:33+00:00

My question is related class design. It is really hard to explain everything here

  • 0

My question is related class design. It is really hard to explain everything here so I am taking an example which is similar to my problem.

Requirements: Customer can execute a single action or he can combine multiple actions.

Based on the above requirements, the classes were structured as below:

interface ICustAction
{
    void Execute();
}
class CustAction:ICustAction
{
    // this class contains a single action to be performed
    public void Execute()
    {
       //should execute customer action
    }
}

class CustActionCollction:ICustAction
{
   // list of actions to be performed
    private List<CustAction> _custActions;



    public void Execute()
    {
        //should execute all the customer action in the list
    }
}

class ExecutionEngine
{
    public void Execute(ICustAction action)
    {
        //executes customer action/ customer action collection based on reference
        action.Execute();
    }
}

New Requirement:
Customer should be able to add CustActionCollection inside CustActionCollection.

Example:
Customer action collection:
customer action 1:
customer action 2:
customer action collection 1: (this action collection might have multiple customer actions)
customer action 3:

Based on these requirements, the updated CustActionCollection class looks like this

 class CustActionCollction:ICustAction
{

   // list of actions to be performed
    private List<ICustAction> _custActions;



    public void Execute()
    {
        //should execute all the customer action in the list
    }
}

Now here is the new requirement where I need expert opinion.

I need to check whether a particular action is defined more than once in a customer action collection??

Customer action collection:
customer action 1:
customer action 2:
customer action collection 1: (this action collection might have multiple customer actions)
customer action 3:

SO, the check should be recursive including all child collection.

Question:

Should I add this check method inside the interface or it should be exclusively for the customer action collection class??

A)If the method is defined in the interface then what will be the signature of the method then implementation for both classes?

B)If the method is not in the interface then what will be the implementation of the method?

I’m Sorry, if I could not explain it properly.

  • 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-25T15:16:33+00:00Added an answer on May 25, 2026 at 3:16 pm

    If I understand your question it seems that checking for duplicates will only need to happen in the case of a CustActionCollection. As a result I think you best implementation is to:

    1. Rely on the Equals implementation to check for CustAction equality. (Doesn’t need to be but makes the most sense in my opinion).
    2. In the CustCollection.evaluate() method, generate a master List of all CustActions and check for duplicates. It will look something like this (this in the class CustActionCollection):

      public void Execute()
      {
          //should execute all the customer action in the list
          if (DuplicatesExist())
          {
              // Handle error
          }
      }
      
      private bool DuplicatesExist()
      {
          List<CustAction> actions = ProcessCollection(this);
      
          for (int x = 0; x < actions.Count; x++)
          {
              for (int y = x + 1; y < actions.Count; y++)
              {
                  if(actions[x].Equals(actions[y])
                  {
                      return true;
                  }
              }
          }
      
          return false;
       }
      
      // Recursively get all customer actions
      private List<CustAction> ProcessCollection(CustActionCollction actions)
      {
          List<CustAction> ret = new List<CustAction>();
      
          foreach (ICustAction action in actions._custActions)
          {
              if (action is CustActionCollction)
              {
                  ret.AddRange(ProcessCollection(action as CustActionCollction);
              }
              else
              {
                  ret.Add(action as CustAction);
              }
           }
      
           return ret;
       }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a design and object structuring related question. Here is the problem statement:
I have following event class. I have a question related to the Property method
I have a simple question related to one-line programming. First an example: function test(a)
This question is related to the one here: configurable dependencies with easy to mock
I have a model which uses acts-as-tree. For example: class CartoonCharacter < ActiveRecord::Base acts_as_tree
Similar to this question: C# Constructor Design but this question is slight different. I
I am working in asp.net MVC2 application and I have question related to design
This question is related to PHPUnit, although it should be a global xUnit design
Related to this Stack Overflow question (C state-machine design) , could you Stack Overflow folks share
I have a question related to C++ design. What are some criteria that you

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.