Generic interface overloading. Valid terminology?
Asked Answered
S

1

12

Here is a very basic example of method overloading , two methods with the same name but with different signatures :

int MyMethod(int a)
int MyMethod(int a, string b)

Now let's say I define two generic interfaces, sharing the exact same name but with different number of type parameters, such as:

IMyInterface<T>
IMyInterface<T1,T2>

Can I say this represents "generic interface overloading" ? Or does the "overloading" term only applies to methods in such a context ? Still it looks kind of very similar to method overloading, in the sense that we are keeping an exact same name but varying the parameters.

If I can't say "generic interface overload/overloading" what can I say about these two different interfaces sharing the same name ?

Thanks and sorry if this is a dumb question, but googling arround "generic interface overload" or "generic interface overloading" doesn't give me much but results concerning interface methods overloading, which is not what I'm interested in.

Stokes answered 19/12, 2012 at 1:27 Comment(4)
I would go with "Generic type parameter overload". Maybe "overload" is the incorrect term.. there may need to be a different way to describe it.Heehaw
I call semantics. It doesn't matter so much what it's called as long as people know what you're talking about.Leech
Not an answer, but I think you'd enjoy reading this answer: https://mcmap.net/q/775002/-net-generics-terminology-open-closed-unbound-constructed .Morrissey
If you read through the MSDN on the Tuple class (msdn.microsoft.com/en-us/library/system.tuple.aspx), it never uses a specific terminology. Indeed, it tends to refer to the different versions as different types. However, it also differentiates them by referring to their "components". So maybe when referring to your generic types, you can use language like "MyMethod type with 2 components" or "MyMethod type with 1 component"?Skiplane
G
10

Types with the same name but a different number of generic type parameters (including zero) are simply different types. The term "overloading" does not apply here. Overloading really only applies to methods belonging to the same type and having the same name but different signatures.


It is very common to have a generic as well as a non-generic interface with the same name (example from the .NET Library):

public interface IList : ICollection, IEnumerable

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable

They are just called generic and non-generic.


The .NET name of a generic type is the name of the type ending with a grave accent (`) and the number of type parameters. For example the type IMyType<T> in C# or IMyType(Of T) in VB is translated to

IMyType`1

internally. The <T> is really just a C# syntactic construction which is translated to an internal .NET name used by the CLR.

IMyType<T,U> would be translated to

IMyType`2

This shows clearly that types with the same name in C# differing only by their number of generic type parameters are in (CLR-) reality types with different names.

Gressorial answered 19/12, 2012 at 2:12 Comment(5)
+1 agree, name<t1> and name<t1,t2> are best consider as TYPE1 and TYPE2Shonna
+1. Thanks (will probably mark as answered soon). It makes sense as it is correct to say that these interface simply are different distinct types. What I don't get is when you say "methods of the same type" ... methods are not types, it does not really make sense (but I somehow get what you mean) While I agree that both of these interfaces are distinct types, they share a similar name, which should, to my mind have a specific terminology in order to point out this fact and the specific "relationship" of these interfaces. Where should we do request for new terminologies ? :)Stokes
I mean belonging to the same type. Sorry for the confusion. (corrected)Gressorial
Thanks for the clarification and the additional edit to your answer.Stokes
Answered ! Still would have liked to be able to talk about these somehow related interfaces using a specific term rather than just "distinct". In fact I realized this when adding a generic interface of the exact same name that another one in my code, but with different type parameters, and I was trying to figure out what to write for a comment for my code commit. I can't say "added an overload for IMyInterface", I will then say "added a new IMyInterface type" ... Someone seing this commit may think this is a brad new interface (which is indeed the case, but not really ;)).Stokes

© 2022 - 2024 — McMap. All rights reserved.