we have some API which will be called either by client A, B, C or DCurrent codedoSomething(String client){if (client.equals(A)){...}else if (client.equals(B)){...}Proposed refactoring 1separate into multiple methods and have each client call the dedicated method such asdoSomethingForClientA()doSomethingForClientB()we need this because internally each method will call other private methods defined in the same classProposed refactoring 2Use strategy (or template) pattern and separate into multiple classes for the clients to callthe method call from client remains doSomething()Which approach is better in the long run? Is there any design pattern to help with option 1 ?or a 3rd option?
Refactoring options - multiple methods in same class or into separate classes
java
Proposed refactoring 2 is better in the long run.This will allow you to extend additional functionality for additional (unforeseen ) client types later, without modifying tested parts of code, for already existing clients.