I have two ways to define constants. First one holds the bunch of static final DataType variables in a class and another by using Enum.
Here is the fist type:
public class TipTipProperties { public static final String MAX_WIDTH_AUTO = "auto"; public static final String POSITION_RIGHT = "right"; } And the usage of these variable will via static call, as an example: TipTipProperties.MAX_WIDTH_AUTO
And the second type is:
public enum TipTipProperties { MAX_WIDTH_AUTO(MaxWidth.AUTO), POSITION_RIGHT(Position.RIGHT); private MaxWidth maxWidth; private Position position; private TipTipProperties(MaxWidth maxWidth) { this.maxWidth = maxWidth; } private TipTipProperties(Position position) { this.position = position; } public MaxWidth getMaxWidth() { return maxWidth; } public Position getPosition() { return position; } public enum MaxWidth { AUTO("auto"); private String width; private MaxWidth(String width) { this.width = width; } public String getWidth() { return width; } } public enum Position { RIGHT("right"), private String position; private Position(String position) { this.position = position; } public String getPosition() { return position; } } } As an example usage: TipTipProperties.POSITION_RIGHT.getPosition().getPosition().
My question is:
- Which one is better OOP and why?
- Is there any alternatives or better approach exists?
Thanks in advance.