I am creating a client side swing app that will have data provided by/from one of many data providers(brokers). The data providers however, have varying ways of perfoming same things e.g.
broker1’s login method
public boolean doLogin(String username, String password);
broker2’s login method
public int login(String username, String password,String sessionId);
For all providers the set of required actions is the same
e.g
login, getstatus, sendRequest, getData, logOff
(but they have different params and return types)
I took a look at the adapter pattern but am unfortunately not able to use it well as the required methods have different parameters.
Is the adapter pattern usable in this case? if so how?
If not what would be the best way of doing this?
Thanks.
Patterns are general guidelines (starting point) of best practices. Many developers “adapts” the patterns to their needs; the important thing is, then, if you must use a pattern, use it consistently throughout your whole application.
Now, to answer your question; yes the adapter pattern can very well be used in your situation. A possible solution (in the like) could be:
Then
Or
Of course this is a very general approach. If you know that one method will be receiving strings for all parameters, you could also have a abstract signature like :
Then your concrete implementation would be :
etc.