0

元従業員が書いたコードをレビューしていて、これを見つけました

public abstract class BaseClass<T, M> 
where T : BaseClass<T, M>, M
where M : IDisposable
{
    protected M PropertyName {get; private set}
    ...
    // T is never used in this class. Only M is used
}

継承されたクラスは次のように定義されます

public class InheritedClass : BaseClass<InhertiedClass, IFooInterface>, IFooInterface
{
   ...
}

IFooInterface : IDisposable {...}

私の質問は、基本クラスがそれ自体から継承するジェネリック型 T を指定するのはなぜですか? この一般的な制約を削除しても何も変わらないので、そもそもなぜそこにあるのだろうと思っていました。私が気付いていない、このような一般的な制約を指定する利点はありますか?

4

0 に答える 0