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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:43:36+00:00 2026-05-10T22:43:36+00:00

I’m not really sure how to title this question but basically I have an

  • 0

I’m not really sure how to title this question but basically I have an interface like this:

public interface IFoo {     string ToCMD(); } 

a couple of absract classes which implement IFoo like:

public abstract class Foo : IFoo {    public abstract string ToCMD(); }  public abstract class Bar : IFoo {     public abstract string ToCMD(); } 

then classes which inherit Foo and Bar:

public class FooClass1 : Foo {     public override string ToCMD()     {return 'Test';} } ///there are about 10 foo classes.  public class BarClass : Bar {     public override string ToCMD()     {return 'BarClass';} } ///about the same for bar classes. 

I am doing this so that when I have my custom list like:

public class Store<T> : List<T>  where T : IFoo {} 

I then can restrict the types that go in it but by having the interface it will still take any type of IFoo.

Something like:

Store<Foo> store = new Store<Foo>(); //Only Foo types will work. store.Add(new FooClass1()); //Will compile.  Store<IFoo> store = new Store<IFoo>(); //All IFoo types will work. store.Add(new FooClass1()); //Will compile. store.Add(new BarClass()); //Will compile. 

My question is: Is this an ok way of going about this? or is there a better way?

EDIT: Picture-> alt text

  • 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. 2026-05-10T22:43:37+00:00Added an answer on May 10, 2026 at 10:43 pm

    The need for an inheritance chain is questionable, in general.

    However the specific scenario of combining an abstract base class with an interface.. I see it this way:

    If you have an abstract base class like this, you should also have a corresponding interface. If you have an interface, then use the abstract base class only where the inheritance chain is sensible.

    That said, if I’m writing a library and this is part of my API/Framework, I will generally include a ‘default implementation’ that can be used as a base class. It will implement the interface methods in a naive, general way, where possible, and leave the rest for inheritors to implement/override as needed.

    This is just a convenience feature of the library though, to assist people who want to implement the interface by providing a functional example that may cover most of what they need to implement already.

    In short, the interface is more valuable than the base class, but a base class might save a lot of time and reduce buggy interface implementations.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and
I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a JSP page retrieving data and when single or double quotes are
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
In order to apply a triggered animation to all ToolTip s in my app,

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.