views:

97

answers:

4
 public class Leaf : IComponent<Leaf>
    {
        //...
    }

Does this type of generic inheritance mechanism have any specific name?

What is the benefit of this type of usage of Generics?

+2  A: 

In the context of C++ at least, there's the moniker the "curiously recurring template pattern".

Brian
+2  A: 

It doesn't have a specific name to my knowledge,

The real benefit, as I see it and as with all thing generics, is type safety. By using the generic interface, you are guaranteeing the implemented methods will be type safe (at least in their definitions).

In my opinion, there is no real reason to use the "normal" interfaces if there is a generic version available.

Alastair Pitts
+1  A: 

Interfaces are not inherited, they are implemented. What you are showing is not an inheritance mechanism; you are implementing an interface that happens to have a generic type parameter.

As for the benefit, I agree with AP Erebus; type safety is the major benefit.

Fredrik Mörk
A: 

I've seen this referred to simply as a self-referencing generic. I know this question is about C# but the best example I know of is the Enum class in Java. An enumeration (for example, exampleEnum) implicitly inherits Enum<exampleEnum>. This allows the base class to implement type-safe code that needs to know the final closed generic type.

Snarfblam