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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:29:50+00:00 2026-06-03T04:29:50+00:00

I have an abstract class ClassA, with an abstract method that takes a paramter

  • 0

I have an abstract class ClassA, with an abstract method that takes a paramter of type ClassB. Several classes derive from it. Now I add another project, which has similar functionality, but needs a slightly different base ClassA, to derive its several classes from. The main difference: The new base class, ClassC, shouldn’t ClassB as argument, but another one, that’s derived from B, ClassD. ClassC should then be used as base by several classes again.

Is this possible? This is more of a question out of curiousity. I know it is possible with generics, by doing this:

public abstract void Method1<T>(T parameter) where T : ClassB;
...
public override void Method1<ClassB>(ClassB parameter) {

Is it possible without generics? And is there any dowside to them, aside from having to type the type twice?

abstract class ClassA
{
    public abstract void Method1(ClassB parameter);
}

class DerivingClasses1 : ClassA
{
    public override void Method1(ClassB parameter)
    {
        // do something
    }
}

// -------

abstract class ClassC : ClassA
{
    // This would have to override Method1 of ClassA somehow,
    // instead of overloading it.
    public abstract void Method1(ClassD parameter);
}

class DerivingClasses2 : ClassA
{
    public override void Method1(ClassD parameter)
    {
        // do something
    }
}

// -------

class ClassB
{
}

class ClassD : ClassB
{
}
  • 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-03T04:29:51+00:00Added an answer on June 3, 2026 at 4:29 am

    In my opinion, the best approach would be to override the base class method with a sealed implementation that invokes the overload with the new parameter type, thereby insulating the user from the type conversion.

    abstract class ClassC : ClassA
    {
        public override sealed void Method1(ClassB parameter)
        {
            this.Method1(parameter as ClassD);
        }
    
        public abstract void Method1(ClassD parameter);
    }
    

    Edit: If used in production, you should perform proper type checking in order to avoid getting unexpected nulls:

    abstract class ClassC : ClassA
    {
        public override sealed void Method1(ClassB parameter)
        {
            if (!(parameter is ClassD))
                throw new ArgumentException(
                    "Parameter must be of type ClassD.", "parameter");
    
            this.Method1((ClassD)parameter);
        }
    
        public abstract void Method1(ClassD parameter);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract parent class which child classes that inherit from it. I
Suppose I have an abstract class Bar that takes a type parameter: abstract class
I have an abstract class that has a virtual method. The method is virtual
I have a bunch of classes extending an abstract Base class. Each subclass takes
I have an abstract immutable base class that defines enforces child classes to be
I have a webservice with a method that takes a parameter of abstract base
I have a base abstract class with several classes which extend and override it,
I have a abstract base C# class with a couple of methods that has
I have an abstract class which contains method for setting header text. It looks
i have an abstract class BaseClass with a public insert() method: public abstract class

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.