I’m writing an Android app that makes heavy use of web services.
I’d like to write a method to add headers to my Http objects (HttpGet, HttpPost, HttpPut, HttpDelete).
I’d like to write 1 method and not 4, since the headers for all will always be the same.
I believe all 4 extend HttpRequestBase. Would the best idea be to write a method that takes an HttpRequestBase as a parameter and cast my various HttpGet, HttpPost, HttpPut, HttpDelete objects to HttpRequestBase and call the method?
Other suggestions?
If all four extend the same base class, then you shouldn’t need to do any casting at all; polymorphism should do what you want. i.e. simply:
I don’t know anything about this library, though. There may be some gremlins that prevent you from doing this (but in which case, it’s a bad library design).