Replace empty method with method from a class where it is used
In the following scenario, I want to replace Class B's (similarly D, E, F,
etc.) method doSomething() with the method in Class A where it will be
used. How would I go about this? Made up some example, hope it gets the
message across
public class B implements GetNames{
public void getNameA(){ return "NameA"; }
public void getNameB() { return "NameB"; }
public void doStuff(){
//print names
doSomething(getNameA(), getNameB());
//print names
}
public void doSomething(String a, String b){}
}
public class A{
public void someMethod(){
B b = new B();
b.doStuff(); //*So I want it to call the method in B but somehow
replace the doSomething method in B with the doSomething method in
A
}
public void doSomething(String a, String b){
//print 'blabla' + a
//print 'blablabla' + b
//concatenate and print
}
}
No comments:
Post a Comment