我有三个具体的课程-
public class ClassA{
public C1 processA(C1 c1){
//lots of ugly code that copies
//one field to another
//return c1
}
public List<C1> processA(List<C1> c1s){
//iterate over c1s
//call process(c1)
//add returned value to list
//return list
}
}
public class ClassB{
public C2 processB(C2 c2, C3 c3){
//lots of ugly code that copies
//one field to another
//return c2
}
public List<C2> processB(List<Pair<C2, C3> pairs){
//iterate over pairs
//call process(c2, c3)
//add returned value to list
//return list
}
}
public class ClassC{
public C4 processC(C4 c4, C5 c5, C1 c1){
//lots of ugly code that copies
//one field to another
//return c4
}
public List<C4> processC(List<Triple<C4, C5, C1> triples){
//iterate over triples
//call process(c4, c5, c1)
//add returned value to list
//return list
}
}
我想删除 process(List...) 方法中的重复。我不关心 processA(C1)、processB(C2,C3)、processC(C4,C5,C1) 方法,它们将保持不变。在重构此代码时我有哪些选择?