interface Tuple {
void method1();
}
class Tuple1 implements Tuple {
@Override
public void method1() {
// some code ....
utilityMethod();
// some code ....
}
// it will be used by subclasses of Tuple only
private void utilityMethod(){
// some code....
}
}
class Tuple2 implements Tuple {
@Override
public void method1() {
// some code ....
utilityMethod();
// some code ....
}
// it will be used by subclasses of Tuple only
private void utilityMethod(){
// some code....
}
}
utilityMethod
将由Tuple
的所有子类使用,我应该把utilityMethod
放在哪里最好?
没有一些令人信服的理由,我将其放在Tuple
中。您可以将其设为默认方法。喜欢,
interface Tuple {
void method1();
// it will be used by subclasses of Tuple only
default void utilityMethod(){
// some code....
}
}