1
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....
    }
}

the utilityMethod will be used by all subclasses of Tuple, where should I put the utilityMethod best?

Guo
  • 1,761
  • 2
  • 22
  • 45

1 Answers1

2

Absent some compelling reasons, I would put it in Tuple. You can make it a default method. Like,

interface Tuple {
    void method1();
    // it will be used by subclasses of Tuple only
    default void utilityMethod(){ 
        // some code....
    }
}
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249