For example, let's say I have this wonderful interface:
public interface BestService {
public String whoIsAGoodService(String serviceName);
}
Going down it's implementation, we can find the following method:
@Override
public String whoIsAGoodService(String serviceName) {
String ipFromName = this.findOutIpFromName(serviceName);
boolean isItReallyGood = this.findOutGoodService(ipFromName);
String intermediateResponse = this.findOutGoodServiceMessage(isItReallyGood);
String finalResponse = this.buildFinalResponse(intermediateResponse);
return finalResponse;
}
The question there is not about code quality (1). My question is:
Is it considered a good/bad practice to keep them in the ServiceImpl class ? Or should we create some class called BestServiceLogic
to handle all those processes ? I would like some pieces of information about what is considered a best practice. My point of view would be that it tends to make service implementation classes very long, clustering all the sub-methods for all the methods being called by the client. But I would like some objective facts about this one.
For some context. I am re-writing legacy code (2) and I would like to figure out the best way to keep things clean and clear on the long-term.
I already read about this question but it treats more about class injection than method dispatching through classes.
(1) I know I could directly return the result of finalResponse
and I don't know about using this.method()
to call private members being a good or bad thing (if you want to enlighten me on the latter, however, I'd be delighted). It is an arbitrary, on-the-fly example.
(2) do not worry, I won't break anything, I wrote tests first.