I have a challenge:
Imagine you have a set of messages like this:
Code / Message
200567 = A new user was created
462001 = Unknown client number
…
I’m trying to find the neatest, lightest, and easiest to maintain way to use this messages in java.
The rules are:
- You need to be able to access the message by its code
- You need to be able to print the code
- You need to be able to easily change the number of a code in the future
Other notes:
- The messages can be in a proprieties file, in other file, in a class, or other place (?), whatever you find better.
- The code can be a integer or a string (Like MSG_423456), whatever you find better.
So, anybody has ideas?
(Sorry about my lousy English)
I would put this in an enumeration.
NEW_USER("String 123", "A new user was created");private String code, message;private MessageType(String code, String message) {this.code = code;this.message = message
}I would go for enumerations because they are to be checked into source control, typically in the environments where I work the properties file is meant to be configured by the individual. Such as an ant build properties file.