I have 2 methods calling same method names:
public void doSomething1(Obj1 obj1) {
obj1.do1();
obj1.do2();
obj1.do3();
}
public void doSomething2(Obj2 obj2) {
obj2.do1();
obj2.do2();
obj2.do3();
}
I would like to extract to "common code" in a third method, this would be possible if I could create a super class of Obj1 and Obj2 but I can't. There is no way make these 2 objects inherit from a super class.
So my question is, is there a way in Java to do this kind of extraction when there is no link between objects, something like:
public void doSomething1(Obj1 obj1) {
refactor(obj1);
}
public void doSomething1(Obj2 obj2) {
refactor(obj2);
}
private void refactor(NewObj newObj) {
newObj.do1();
newObj.do2();
newObj.do3();
}
do1()methods are the same method, not just two methods with the same name.interface?