I have a class. The thing that this class is meant to represent is such that we may speak about such things being equal to each other, and we may also come up with a scheme to rank them for purposes of comparison.
However, it so happens that it is rare that one feels the need to rank these things, but one often needs to check if two such things are equal.
So, I can implement both IEquatable
for my class as well as IComparable
. While IComparable
provides some extra functionality, it is very unlikely that anyone will care about this extra functionality. Neither one seemingly provides a clear advantage, either logically or functionality-wise.
Which interface should I implement, IEquatable
, IComparable
, or both? Why? (I am specifically wondering about framework-wide implications either interface)
This question is similar, but the answers only state the obvious, which doesn't help me.
In case you are wondering, the class is meant to represent a nucleotide. Nucleotides can readily be equated, but they can also be compared (eg. alphabetically).