By hstaudacher
via eclipsesource.com
Published: Jul 17 2012 / 04:49
A common task in object oriented programming is comparing two objects for the purpose of sorting. In Java the useful Comparable> Interface exists. I’ve found myself implementing the compareTo method from this Interface plenty of times. But there is something that bothers me everytime: the complexity of the code this implementation creates. Let me explain.
One of my goals is to always write easily readable code. But this is really hard when implementing a compareTo method for an object with more than two fields. Let’s take a look at an example.
Add your comment
Voters For This Link (18)
-
hstaudacher -
fluffi -
tseidel@eclipsesource.com -
bmuskalla -
ralfstx -
Cursedboy -
allweil -
bloid -
mswatcher -
johnmunsch -
evensonic@gmail.com -
ruediger.herrmann@gmx.de -
slaux -
zynasis -
tdziurko -
irbull -
carrion -
kingrose