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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:43:35+00:00 2026-06-03T00:43:35+00:00

I have two interfaces; ISet and ISet<T> Both implement Add, Remove and Clear but

  • 0

I have two interfaces; ISet and ISet<T>

Both implement Add, Remove and Clear but with different argument types; object and T.

Now I have two options. Either let ISet<T> inherit from ISet, or let them be isolated from each other.

One great benefit of having ISet<T> inherit from ISet is of course that I always can use a ISet<T> where-ever I need a ISet. But doing so I also have to add the “new” modifier to the members with a T-parameter. I don’t like the “new”-modifier very much, but maybee this is the better option in this case?

It feels odd having a ISet<T> that isn’t also a ISet. That’s the logical assumption. I can’t really say excatly why I don’t like the “new”-modifier. It’s like with the “goto”-keyword. I just try not to use it.

What do you think I should go with here? Inherit or not?


In .NET we have ICollection<T> and ICollection which doesn’t inherit. Neither do IList<T> and IList. But IEnumerable<T> inherit from IEnumerable.


I know about the ISet-interface that allready exist (This was just an example)

  • 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-03T00:43:37+00:00Added an answer on June 3, 2026 at 12:43 am

    The only thing that inheriting from the non-generic form would really buy you is the ability to perform certain operations on an ISet<T> without having to know at compile time what the T was. One couldn’t add items to such a set in type-safe manner, and reading might be somewhat inefficient (since value types would have to be boxed), but methods or properties like Count could be perfectly useful.

    My suggestion would be that you define multiple interfaces something like this (note that I’m adding some members that you don’t have, since your collection is at moment write-only and thus not very useful)

    interface ICountable { int Count {get;} }
    interface IClearable { int Count {get;} }
    interface IAppendable<in T> { void Add(T item); }
    interface ICountableEnumerable<out T> : IConvertableToEnumerable, ICountable 
      {IEnumerable<T&gt CopyAsEnumerable();}
    interface IFetchable<out T> { T FetchAndRemove(ref bool wasNonEmpty); }
    interface ISet<T> ICountable, IClearable, IAppendable<T>, IFetchable<T>,
              IConvertableToEnumerable<T>; 
    

    Such interface segregation makes it possible to use covariance and contravariance to the extent that it makes sense.

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

Sidebar

Related Questions

If I have two interfaces , both quite different in their purposes , but
I have two interfaces IHeaderRow , and IDetailRow I then have an object that
I have the following two interfaces: public interface IMembershipProvider { object Login(ILoginProviderParameters loginParameters); void
In my system I have two different projects, one defining its interfaces and another
I have a class that instantiates two classes which implement interfaces. I want one
I have two interfaces IDto1 and IDto2. IDto2 inherits IDto1. Both interfaces are for
I have a question about those two interfaces in Java. Set extends Collection, but
I have two interfaces A and B and B is extending A. I have
I have two Java interfaces and one implementing class. (I have used Eclipse to
I have two distinct (no inheritance) interfaces: IInvestable and IPricable and two classes: IndexClass

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.