I have a software setup with 2 layers, a core layer and a customer specific layer. The core layer has defined constants which the customer specific layer should be able to extend. More specific:
public class CoreConstants
{
public static long CORE_CONSTANT_1 = 1;
public static long CORE_CONSTANT_2 = 2;
}
The customer specific layer should be able to add constants which are only used in the customer specific layer. Idea:
public class CustomerConstants extends CoreConstants
{
public static long CUSTOMER_CONSTANT_1 = 1000; // starting range = 1000
}
Is there a more common way to handle this?
More info: The reason for inheritance is to define the starting range of the customer specific constants. In the CoreConstants class I could set the starting value for customer specific constants. Customer specific constants could then be defined like:
public static long CUSTOMER_CONSTANT_1 = customStartValue + 1;
public static long CUSTOMER_CONSTANT_2 = customStartValue + 2;
Integer constants are generally better replaced with
enums, and you can achieve what you want using interfaces on enums.You could perhaps improve the design by using delegation within the enums, using an
IntConstantclass. Unfortunately for your case, you cannot extend an enum. The result is a bit of code duplication in the enum classes.Otherwise, if you want to stay with the public static int model, then use an interface instead of a class, and finalize the constants.