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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:03:54+00:00 2026-05-25T20:03:54+00:00

I have a nongeneric interface to a generic class group. I have a method

  • 0

I have a nongeneric interface to a generic class group. I have a method which uses covariance to return a strongly typed instance in a class derived from an abstract implementation of the non-generic class group.

So basically with this setup, I have a number of classes, e.g. ActualThing1 and ActualThing2. These classes have a Clone method which returns a strongly-typed clone of themselves.

Below is how I’ve structured the interface & classes. I am not sure this is right.
Normally, I wouldn’t have the non-generic abstract class at all. But this is necessary because there is a situation where I have to do something to child objects, referencing an internal method _SomethingNeededInternally. This can’t be done using the interface, since it’s protected, nor can it be done from inside the generic class, since the children might not be the same type (they might be a different type derived from the interface). Hence the non-generic base class Something.

This works, but what doesn’t quite make sense to me is the explicit implementation of ISomething.Clone that is needed in my abstract Something class. It has to be there, but it shouldn’t be implemented, since I want that implementation deferred to the generic class that derives from it. But there’s no such syntax as abstract ISomething ISomething.Clone().

But that code (where the exception is throw) can’t ever execute, can it, since I don’t have any non-generic implementations of this object?

I guess I’m wondering if there is a better way to do this, because it seems not right. That is, I am depending on the fact that a non-generic class is never created from the interface, which smells funny.

public interface ISomething
{
    // ...
    ISomething Clone();
}

public abstract class Something: ISomething 
{
    ISomething ISomething.Clone()
    {
        throw new Exception("This should not be happening");
    }
    protected int _SomethingNeededInternally;
}

public abstract class Something<T>: Something, ISomething where T: ISomething, new()
{
    public abstract T Clone();

    ISomething ISomething.Clone()
    {
        return Clone();
    }
}

public interface IActualThing {} // this could be any interface

public class ActualThing: Something<ActualThing>, IActualThing
{
    public override ActualThing Clone() 
    {
        return new ActualThing(); // do cloning here
    }
}
  • 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-25T20:03:55+00:00Added an answer on May 25, 2026 at 8:03 pm

    Would adding required method as implementation of Clone work for you?
    (I’m still not exactly sure what your whole problem is, this will just solve syntax for abstract explicit interface implementation.)

    public abstract class Something: ISomething  
    { 
        ISomething ISomething.Clone() 
        { 
            return CloneYouMust();
        } 
        abstract ISomething CloneYouMust();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class which is non-generic with a derived generic class. The
I have a generic class DirectorySource<T> which depends on an interface IDirectorySearch<T> . Both
Lets say I have a class, which implements a generic interface public interface IItem
I have a generic method (in a non generic class) returning elements. public IEnumerable<T>
I have a main page which uses a ViewModel I have created: public class
I have a generic object factory FactoryBase<T> with a factory method: public abstract class
I'm trying to create an open instance delegate for a generic interface method, but
I have a few generic classes that implement a common non-generic interface. I create
I have a class that has an instance property on it like below Public
I have the following interface which I'm trying to make COM-visible. When I try

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.