Java interface design: where should I put a lot of duplicate code that will be used by all subclasses?
interface Tuple {
void method1();
}
class Tuple1 implements Tuple {
@Override
public void method1() {
utilityMethod();
// some code ....
}
private void utilityMethod(){
// some code....
}
}
class Tuple2 implements Tuple {
@Override
public void method1() {
utilityMethod();
// some code ....
}
private void utilityMethod(){
// some code....
}
}
Interface can't define final or private method, the utilityMethod is private and it shouldn't be overrided. The utilityMethod will be used by all subclasses of Tuple, where should I put the utilityMethod best?