I have a class containing 10 methods that do almost the same thing except for one key event. The following are two examples:
Public String ATypeOperation(String pin, String amount){
doSomething();
doMoreStuff();
requestBuilder.buildATypeRequest(pin, amount);
doAfterStuff();
}
Public String BTypeOperation(String name, String sex, String age){
doSomething();
doMoreStuff();
requestBuilder.buildBTypeRequest(name, sex, age);
doAfterStuff();
}
As you can see from the above methods, they are similar, except for calling the various methods provided by requestBuilder. The remaining 8 are also similar. There is a lot of duplicate code here. I feel that there is a better way to implement this, but I donβt know how to do it. Any ideas or suggestions are welcome.
Thanks Sarah
source
share