java - Using constants across the application -
i have few constant values refer across application. creating class below snippet.
public class styles { public static final string tablestyle = "tablegrid"; public static final string fontfamily = "calibri"; public static final string headerstyle = "heading2"; public static final string footerstyle = "heading3"; public static final string tableheaderstyle = "heading1"; public static final string tabledatafontfamily = "cambria"; public static final int tableheaderfontsize = 16; public static final int tabledatafontsize = 12; }
i assigning values in , referring them styles.headerstyle
. doubt is, way or there better approach achieve this? enum
?
thanks in advance.
it depends on nature of application, in cases not practice have collection of constants in way, difficult tell without knowing context of application. btw, are sure you'll never (or never) change things "fontfamily"?
of course enum little less verbose , more functional:
public enum styles { table_style("tablegrid"), font_family("calibri"), header_style("heading2"), footer_style("heading3"), table_header_style("heading1"), table_data_font_family("cambria"), table_header_font_size("16"), table_data_font_size("12"); private string value; private styles(string value) { this.value = value; } public string getstringvalue() { return value; } public int getintvalue() { return integer.valueof(value); } }
Comments
Post a Comment