An interface implementation in which generic tools are based on an interface

I am currently reorganizing my code so that all important classes implement the interface (to test for health). I came across a class that implements IComparable (non-templated); sort of:

public MyClass : IComparable
{
    public int CompareTo(object obj)
    {
        MyClass cObj = obj as MyClass;
        if (cObj == null) { throw new ArgumentException(); }
        // etc.
    }
}

I want to combine it and use generics while I am in it; something like that:

public IMyClass : IComparable<IMyClass>
{
    // Other methods here
}

public MyClass : IMyClass
{
    public CompareTo<IMyClass>(IMyClass other)
    {
        ...
    }
    // Other methods here
}

But then, ideally, it MyClassshould implement IComparable<MyClass>(and then subclasses MyClassshould implement IComparable<MySubClass>).

All this to ask a few questions:

, ? ? MyClass IComparable<MyClass>, , IComparable<IMyClass>? - "" -, ?

+5
2

, ? , 0 , .

IClass, IComparable, IComparable.

P.S. " ". factory , , , . , ; Moles.

+2

: .

, (IMyClass ), . : , . , , .

, IComparable, , . , , .

0

All Articles