Preface: I'm posting this on behalf of a friend (who's apparently to shy to post it himself), I browsed through the related questions and I didn't seem to find any duplicate.. But do note that I don't know Java at all so I apologize in advance if this is a duplicate!
This is part of the code:
public class ElencoEsami implements Comparable{
private ArrayList<EsameMedico> a = new ArrayList<EsameMedico>();
private Comparable comparatore;
public ElencoEsami() {
}
public void addEsame(EsameMedico e) {
if (a.isEmpty()) {
a.add(0,e);
return;
}
for(int i=0;i<a.size();i++) {
if (a.get(i).getData().after(e.getData())) {
a.add(i,e);
break;
}
}
a.add(e);
}
public int compareTo(Object o) {
// ?????
}
}
My friend wants to implement "addEsame" so that it maximizes code reusability, in particular he wants to be able to change the way the list is ordered (right now it's ordered by name) simply by adding a new class (a comparator class I believe? Or at least that's how I would do it in C++).
Thank you!