I have ~30 resources each having ~10 attributes. I want to store some information about each attribute. Ex: its multiplicity, it RW (Read/Write), RO (Read only), longName, shortname.
So I was thinking of storing it in a Enum like:
public enum Attributes {
U_RESOURCETYPE(true, "RW", "resourceType", "rt"),
U_RESOURCEID(false, "RO", "resourceID","ri"),
//...
}
But this lead to 300 constants (30 resources * 10 attributes).
I could also use a config file or a Singleton Enum with a Map as member.
What is the best possible way to achieve this ??
Best Answer
I assume these are really constants, not configuration values - i.e. they don't change between invocations or deployments.
In that case I'd store it in Java files - no complicated parsing from the config file, you can leverage type safety etc.
Your approach with enums is fine for a lot of cases, but the problem here is the number of attributes - enum constructor contains too many arguments so it's easy to get lost in them, switch order of arguments etc.
In your case I'd probably create something like this:
It gives you typesafety and clarity, but it's a bit more laborious ...