Use properties file instead of static final variables

后端 未结 6 1505
轮回少年
轮回少年 2021-02-08 03:05

I have many classes with static final fields which are used as default values or config. What is best approach to create global config file? Should I move these fields to single

6条回答
  •  星月不相逢
    2021-02-08 03:32

    Both the approches are fine:

    1. Have a static class with required final fields.

    2. Have a singelton but save it from multiple threads appropriately.

    3. if possible use enum over static fields. This way you can group related fields together.

    If these are application level values, i'll prefer static class over singelton.

    and, you should decide if these are const values or configuration value that differ from time to time.

提交回复
热议问题