目前我声明,像这样我的所有静态字段:OOP设计:静态字段
public static final int EXAMPLE_OF_STATIC_FIELD = 0;
说我有一个代表,可以在类中ocurre所有错误字段的基类:
public class Base {
public static final int ERROR_1 = 0;
public static final int ERROR_2 = 1;
public static final int ERROR_3 = 2;
}
如果我扩展这个基类,我想更多的Error types
添加到类,我会做到以下几点:
public class OffSpring extends Base {
public static final int NEW_ERROR_1 = 3;
}
对于我宣布新的Error types
,我需要知道基类的Error types
的价值,这在我看来不是很方便,因为我可以不经意地在Base class
的后代类别中声明Error Type
值为Base class
的Error type
。例如:
public static final int NEW_ERROR_1 = 0;
这将是相同的
public static final int ERROR_1 = 0;
这会冲突...
我想,也许使用Enum Class
,然而事实证明,你不能扩展它。 Can enums be subclassed to add new elements?
另一种选择是使用字符串值类型,而不是int值类型的所有静态字段,但是这并不是一个非常有效的解决方案......
我如何添加更多领域的一个阶级的后代,没有他们与超级阶级冲突?
如果您直接定义常量,总会有错误的可能性。怎么样使用GUID? – SJuan76