Issue
I have a Spring Boot app that makes calls to several end-points of a third-party app. "start_date" is passed as a request parameter in most of the calls. Today the string is inlined in classes that make the calls (there is one class for each third-party end-point). I would like to DRY the Strings.
If the calls were made from a single class, I could have a private static final START_DATE = "start_date"
in that class. But the calls are in multiple classes. Is there a better solution than have a class dedicated to holding the values?
Note: Besides "start_date" there are 3 or 4 other request parameters that are also shared.
Solution
You can simply have a class to hold those values, but rather than using private
, using public
. As an example:
public class ApiConstants {
public static final String START_DATE = "start_date";
}
You can then use the parameters:
ApiConstants.START_DATE
Answered By - Magd Kudama
Answer Checked By - Gilberto Lyons (JavaFixing Admin)