Development tips ---------- definition of constant classes in projects

Source: Internet
Author: User

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!

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.