Problem:
All developers know that constant classes are the most common way to define data dictionaries. However, with the development time of the project and the change of the development team, there will often be a particularly hard-pressed situation in step 2. The first case is that a variety of constant classes can be seen everywhere in the project; the second case is that a constant class defines a lot of constants, and even some exceed 100. The disadvantages of these two cases are estimated to be very clear to everyone. The first is code discretization, redundancy, and difficult to maintain; the second is difficult to maintain, it is difficult to find the constants you need when using IDE.
Solution:
1. Use static internal classes to group constants (multi-level groups are supported, but a maximum of three levels are recommended)
2. External files (not discussed here)
3. Others (need to be found again)
Sample Code:
Package COM. xxw. java. designpattern. pojo;/*** always-on mode, note that the common constant classes of the ** Promotion Project * @ author xuxuewen */public class promotionconstant {/***** @ author xuxuewen * activity type */public static class activitytype {/** * Not started */public static final string activity_one = "1 "; /*** in progress */public static final string activity_two = "2";/*** sold out */public static final string activity_three = "3 "; /***** ended */public static final string activity_four = "4 ";} /***** @ author xuxuewen * Brand ID */public static class brandid {/*** brand 1 */public static final integer brand_one = 1; /*** brand 2 */public static final integer brand_two = 2;/*** brand 3 */public static final integer brand_three = 3; /*** brand four */public static final integer brand_four = 4 ;}}
Effects of reference:
Note:
The above text is for the convenience of personal record summary!