A factory method pattern will only be necessary if you want/need to provide an exact implementation of IRestClient
based on some arguments. Since this doesn't seem to be your case, you will be good by programming oriented to interfaces. So, instead of having this:
RestClient restClient = new RestClient();
restClient.foo("bar");
You will have this:
//declare the variable as interface
//assign the value with the class implementation
IRestClient restClient = new RestClient();
restClient.foo("bar");
So if you need a new implementation, just change the current implementationto the desired one:
IRestClient restClient = new FooRestClient();
//rest of the code remains intact
restClient.foo("bar");
If you want to move this into Factory Method Pattern, then you will have something like this:
class RestClientFactory {
public static IRestClient defaultRestClient() {
return new RestClient();
}
public static IRestClient createRestClient(String name) {
String realName = name.toLowerCase();
switch(realName) {
case "foo":
return new FooRestClient();
case "bar":
return new BarRestClient();
//and on...
default:
return defaultRestClient();
}
}
}
And then you will have to initialize the instance by calling the respective method from the factory:
IRestClient restClient = RestClientFactory.createRestClient("foo");
//rest of the code remains intact
restClient.foo("bar");