Posted By:
Christopher_Koenigsberg
Posted On:
Tuesday, July 16, 2002 08:28 AM
If they are just "constants", then what "config object" do you need for the constructors?
Can you have the constructor just take a string arg, and then call it for each instance in the declaration? (e.g.
public class ViewMode {
private final String name;
private ViewMode(String name)
{this.name = name; }
public String toString()
{return name; }
public static final ViewMode TEXT = new ViewMode('text');
public static final ViewMode DETAILS = new ViewMode('details');
......
}
In Josh Bloch's maximally cool book "Effective Java" (ISBN 0-201-31005-8, Sun Java Series, Addison Wesley), on p. 105 under "Item 21: Replace enum constructs with classes" he does recommend what you are doing, and gives an example (he calls it the "typesafe enum pattern".