I'm new to Java class design and need help with the following:
Example scenario: I want to pass the company name and email to the BaseEmailMessage class, and fetch these values from the application.properties file.
I also have static variables SIGN_UP_URL and PASSWORD_RESET_URL in the SignUpEmail and PasswordResetEmail classes, respectively, and I need to fetch these from the same properties file.
abstract public class BaseEmailMessage {
// Need to fetch these from application properties
// as they are common for all email types
private String COMPANY_NAME;
private String COMPANY_EMAIL;
// constructor, methods, getters, and setters...
}
@Component
public class SignUpEmail extends BaseEmailMessage {
// Need to fetch this from application properties specific to this class only
private static final String SIGN_UP_URL;
}
@Component
public class PasswordResetEmail extends BaseEmailMessage {
// Need to fetch this from application properties specific to this class only
private static final String PASSWORD_RESET_URL;
}
How can I achieve this in a clean and maintainable way? Any best practices to improve the maintainability of this code?
Thanks!
I tried autowiring the Environment instance to the classes, but not sure should I move with that approach or not?