My app may compare instances of any two sub-classes of the same abstract parent class. I want them compared as follows:

1. If they are different sub-classes, the parent class should do the comparison.
2. If they are the same sub-class, the sub-class should do the comparison.

The classes will be compared by a TreeMap, so I have a choice of using a Comparator, or implementing Comparable (or both?).

I can think of several ways to do this, but they are all a bit messy and error-prone. Is there an elegant solution?

Thanks in advance...