Constant values


I would like to know about something like a code style.

I wonder why the first parameters (String key) passed in the method appendQueryParameter are not all defined as constant values like “PARAM_EXTRAS”.
I think it would be better if you also defined “method” and “api_key” as static constant values in terms of code style.

String url = Uri.parse(ENDPOINT).buildUpon()
.appendQueryParameter(“method”, METHOD_GET_RECENT)
.appendQueryParameter(“api_key”, API_KEY)
.appendQueryParameter(PARAM_EXTRAS, EXTRA_SMALL_URL)

Could somebody explain why?


I just came here to have this exact question answered. Finding no answer to yours, I decided to endure the pain of critical thinking. I concluded that the Flickr API contract must guarantee that the endpoint and API key parameters be constant for the life of the API; all consumers would break if they changed. But the “extras” could be variable, allowing the API to offer more features over time. For example, what if a new photo type XXXXL became available? Just accept a new parameter key: url_xxxxl.

I went to the Flickr API documentation and sure enough, “extras” are defined in the API as “currently supported fields!” So this class is just reflecting the Flickr API specification.