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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:06:43+00:00 2026-06-08T18:06:43+00:00

I would like to specialise a base class by adding new events and methods

  • 0

I would like to specialise a base class by adding new events and methods to it. For example, class B inherits from class A. However, if in code I hold a reference to my class B instance as its base type, A. Am I required to downcast everytime I need to access something from it from B, e.g. subscribe to EventB1, or call MethodB1?

if (obj is B) 
{ 
  B m = (B)obj;
  m.EventB1 += EventHandlerB1; 
}

Also, if I have a switch statement in my base class as above. Is it bad practice to add more cases to it in B?

Class A
{
  public event EventHandler EventA1

  public void MethodA1()
  {
    //some code
  }

  protected virtual void ProcessWorkItem(workItem type)
  {
    switch (type)
    {
      case workItem.A1:
        ..
        break;
      case workItem.A2:
        ..
        break;
      case workItem.A3:
        ..
        break;
    }
  }
}

Class B : A
{
  public event EventHandler EventB1

  public void MethodB1()
  {
    //some code
  }

  protected override void ProcessWorkItem(workItem type)
  {
    base.ProcessWorkItem(type);

    switch (type)
    {
      case workItem.B1:
        ..
        break;
      case workItem.B2:
        ..
        break;
      case workItem.B3:
        ..
        break;
    }
  }
}
  • 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-06-08T18:06:44+00:00Added an answer on June 8, 2026 at 6:06 pm

    Am I required to downcast everytime I need to access something from it from B, e.g. subscribe to EventB1, or call MethodB1?

    Absolutely. This should tell you there’s a design smell here. It doesn’t mean it’s necessarily bad, but it should at least prompt you to consider whether there’s a cleaner approach.

    Also, if I have a switch statement in my base class as above. Is it bad practice to add more cases to it in B?

    It’s hard to tell without knowing more about what it’s trying to do. It’s not clear whether using composition instead of inheritance would help you here, but it’s usually something worth thinking about. You may also want to consider using interfaces – both A and B could implement the same interface, with B composing an A if required. Maybe. It’s hard to tell 🙂

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

Sidebar

Related Questions

Base class MessageHandler has derived classes. They would like to pass messages to each
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like to know the c# code to actually retrieve the IP type: Static
I would like to specialize a template method for a class C that is
I have a class template Z that I would like specialize when passed a
I am attempting to store objects derived from a templated base class in an
In building a class structure, I would like to have derived classes potentially posses
I have a set of classes I derive from a base class as following
Hallo! I would like to specialise only one of two template types. E.g. template
Would like a for loop in jquery so that: For every hover_link: show hidden

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.