I want to simplify the selection of a specific predefined object.
I currently have an enum defined as
ArtworkType { Poster, Banner, Other }
And I want to add attributes to these ArtworkTypes so that I can use them in code elsewhere. The ArtworkTypes attributes are either predefined static labels or are populated from an external configuration file, which is populated with the Properties () class.
Ideally, I want to do something as simple as
ArtworkType.Poster.getWidth();
If I need to use the last class, I think it will be harder to use something like
ArtworkType.getWidth(TypeEnum.Poster);
EDIT: Thanks for the answers below, I come to the conclusion that while I can do this with Enum, it's probably better to use an external class (like ArtworkUtil) to retrieve the attributes that I need.
This is an example of the enumeration code that I have created so far (validation error omitted):
public enum ArtworkType { Poster("poster"), Banner("banner"), Other("other"); private String type; private Dimension dimension; private ArtworkType(String type) { this.type = type; this.dimension = new Dimension(Properties.getProperty("width."+type), Properties.getProperty("height."+type); } public Dimension getDimension() { return dimension; } }
Although I understand that this contradicts the principles of strict Enums, since the values associated with Enum are static (at the time of application), it can be less than two evils.
The only other approach I can come up with is to create the "ArtworkUtil" class, which creates a collection and fills all the necessary attributes into an object and stores them in the collection.
Access to this class in code will make it much more unreadable (unless I miss something?)