I'm not sure how exactly your objects/interfaces are composed together, nor are you very clear on how you want to send this version to the server. The normal approach with REST API versions is to put the version into the URI, sort of like example.com/service/v8/...
.
In that case, maybe you can use a decorator object that that can wrap this WebChannel
(I am presuming that is the type you would call something like .get("/some/url")
on). Your decorator would be able to 'inject' additional data.
You call decoratedObject.setURLPreFix("/some_serivce/v3")
, then decoratedObject.get("/some/url")
, the decorator function would be implemented something like...
class WebChannelDecorator{
WebChannel channel;
String urlPrefix = "";
WebChannelDecorator(WebChannel c){
channel = c;
}
/* methods you want to work just the same */
T foo(args){
return channel.foo(args);
}
/* methods you want to 'decorate' */
T get(String url){
return channel.get(urlPrefix + url);
}
void setURLPrefix(String prefix){
urlPrefix = prefix;
}
}
This may not actually be called the decorator pattern, but the idea is what matters, not what you call it.