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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:05:06+00:00 2026-05-14T07:05:06+00:00

For my understanding purpose i have implemented Chain-Of-Responsibility pattern. //Abstract Base Type public abstract

  • 0

For my understanding purpose i have implemented Chain-Of-Responsibility pattern.

//Abstract Base Type

public abstract class CustomerServiceDesk
{
 protected CustomerServiceDesk _nextHandler;
 public abstract  void ServeCustomers(Customer _customer);
 public void SetupHadler(CustomerServiceDesk _nextHandler)
 {
          this._nextHandler = _nextHandler;
 }
}

 public class FrontLineServiceDesk:CustomerServiceDesk
 {
     public override void ServeCustomers(Customer _customer)
     {
        if (_customer.ComplaintType == ComplaintType.General)
         {
           Console.WriteLine(_customer.Name + " Complaints are registered  ; 
           will be served soon by FrontLine Help Desk..");
         }

        else 
        {
          Console.WriteLine(_customer.Name + " 
          is redirected to Critical Help Desk");

          _nextHandler.ServeCustomers(_customer);
        }

        }
  }
public class CriticalIssueServiceDesk:CustomerServiceDesk
{
    public override void ServeCustomers(Customer _customer)
    {
        if (_customer.ComplaintType == ComplaintType.Critical)
        {
            Console.WriteLine(_customer.Name + 
            "Complaints are registered  ; will be served soon 
             by Critical Help Desk");
        }
        else if (_customer.ComplaintType == ComplaintType.Legal)
        {
            Console.WriteLine(_customer.Name +
            "is redirected to Legal Help Desk");
            _nextHandler.ServeCustomers(_customer);
        }
    }
}

public class LegalissueServiceDesk :CustomerServiceDesk
{
    public override void ServeCustomers(Customer _customer)
    {
        if (_customer.ComplaintType == ComplaintType.Legal)
        {
            Console.WriteLine(_customer.Name + 
            "Complaints are registered  ; 
             will be served soon by legal help desk");
        }
    }
}


public class Customer
{
    public string Name { get; set; }
    public ComplaintType ComplaintType { get; set; }
}


public enum ComplaintType
{
    General,
    Critical,
    Legal
}

void Main()
{
CustomerServiceDesk _frontLineDesk = new FrontLineServiceDesk();
CustomerServiceDesk _criticalSupportDesk = new CriticalIssueServiceDesk();
CustomerServiceDesk _legalSupportDesk = new LegalissueServiceDesk();
_frontLineDesk.SetupHadler(_criticalSupportDesk);
_criticalSupportDesk.SetupHadler(_legalSupportDesk);

Customer _customer1 = new Customer();
_customer1.Name = "Microsoft";
_customer1.ComplaintType = ComplaintType.General;

Customer _customer2 = new Customer();
_customer2.Name = "SunSystems";
_customer2.ComplaintType = ComplaintType.Critical;

Customer _customer3 = new Customer();
_customer3.Name = "HP";
_customer3.ComplaintType = ComplaintType.Legal;

_frontLineDesk.ServeCustomers(_customer1);
_frontLineDesk.ServeCustomers(_customer2);
_frontLineDesk.ServeCustomers(_customer3);
}

Question

Without breaking the chain-of-responsibility ,how can i apply delegates and events to rewrite the code?

  • 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-14T07:05:06+00:00Added an answer on May 14, 2026 at 7:05 am

    If I understand you correctly…what you could do is remove the SetupHandler method and introduce an OnElevateQuery event were your CriticalHelpDesk object could handle the FrontLineHelpDesk.OnElevateQuery event and your LegalHelpDesk object could handle the CriticalHelpDesk.OnElevateQuery event. The OnElevateQuery event could pass the customer in the event args.

    Example

    public abstract class CustomerServiceDesk
    {
        public delegate void ElevateQueryEventHandler(Customer c);
        public event ElevateQueryEventHandler OnElevateQuery;
        public abstract void ServeCustomer(Customer c);
    }
    
    public class FrontLineServiceDesk : CustomerServiceDesk
    {
        public override void ServeCustomer(Customer c)
        {
            switch (c.ComplaintType)
            {
                case ComplaintType.General:
                    Console.WriteLine(c.Name + " Complaints are registered; will be served soon by FrontLine Help Desk");
                    break;
                default:
                    OnElevateQuery(c);
            }
        }
    }
    
    public class CriticalIssueServiceDesk : CustomerServiceDesk
    {
        public override void ServeCustomer(Customer c)
        {
            switch (c.ComplaintType)
            {
                case ComplaintType.Critical:
                    Console.WriteLine(c.Name + " Complaints are registered; will be served soon by Critical Help Desk");
                    break;
                case ComplaintType.Legal:
                    OnElevateQuery(c);
                    break;
                default:
                    Console.WriteLine("Unable to find appropriate help desk for your complaint.");
                    break;
            }
        }
    }
    
    public class LegalIssueServiceDesk : CustomerServiceDesk
    {
        public override void ServeCustomer(Customer c)
        {
            if (c.CompliantType == CompliantType.Legal)
            {
                Console.WriteLine(c.Name + " Complaints are registered; will be served soon by Legal Help Desk");
            }
            else
            {
                // you could even hook up the FrontLine.ServeCustomer event 
                // to the OnElevateQuery event of this one so it takes the 
                // query back to the start of the chain (if it accidently ended up here).
                Console.WriteLine("Wrong department");
            }
        }
    }
    

    Usage

    CustomerServiceDesk _frontLine = new FrontLineServiceDesk();
    CustomerServiceDesk _criticalLine = new CriticalLineServiceDesk();
    CustomerServiceDesk _legalLine = new LegalLineServiceDesk();
    // hook up events
    _frontLine.OnElevateQuery += _critialLine.ServeCustomer;
    _criticalLine.OnElevateQuery += _legalLine.ServeCustomer;
    
    Customer _customer1 = new Customer(); 
    _customer1.Name = "Microsoft"; 
    _customer1.ComplaintType = ComplaintType.General; 
    
    Customer _customer2 = new Customer(); 
    _customer2.Name = "SunSystems"; 
    _customer2.ComplaintType = ComplaintType.Critical; 
    
    Customer _customer3 = new Customer(); 
    _customer3.Name = "HP"; 
    _customer3.ComplaintType = ComplaintType.Legal;
    
    _frontLine.ServeCustomer(_customer1);
    _frontLine.ServeCustomer(_customer2);
    _frontLine.ServeCustomer(_customer3);
    

    However, as the query type is based on the enum ComplaintType have you considered using perhaps a HelpDeskFactory which could return a generic interface e.g. IHelpDesk. Sounds like you could also use the Strategy Pattern for this particular example.

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

Sidebar

Related Questions

I am reading some assembly for MASM and I have trouble understanding the purpose
Can you give me an almost overly simplistic understanding of abstract class vs inheritance
If i want to create a class ( just for testing and understanding purpose)
I have a base class which has a method for moving files to appropriate
I'm seeing it pop up more and more and not really understanding the purpose
As far as my understanding after reading and researching, the purpose of using salt
I have difficulty in understanding the use of union in C. I have read
The purpose of this question is to confirm (or not) my understanding of the
I'm having trouble understanding what the purpose of the virtual keyword in C++. I
I have the following XML <OrderReport> <Item> <Promotion> <Component> <Type>Principal</Type> <Amount currency=USD>-0.25</Amount> </Component> <Component>

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.