I have a class A and class B as below :
class A {
public String myMethod(){
// do-something
return send();
}
public String send(){
// sending for A;
}
}
class B {
public String myMethod(){
// do-something
return send();
}
public String send(){
// sending for B;
}
}
Now the myMethod() is same in both the class but the implementation for send() method is different for class A and B. I am trying to implement the myMethod() inside a Utility class to avoid the duplication of method logic.
class Util {
public String myMethod(){
// do-something
return send();
}
}
But while calling the send(), how would I identify which object actually calls the method so that I can redirect to the appropriate send() method. Do I need the instanceOf in java or or what is a better approach for this problem.