Is there anything wrong with a class with all static methods?

后端 未结 16 1269
余生分开走
余生分开走 2021-01-30 16:43

I\'m doing code review and came across a class that uses all static methods. The entrance method takes several arguments and then starts calling the other static methods passin

16条回答
  •  轮回少年
    2021-01-30 17:16

    It depends on whether the passed arguments can really be classified as state.

    Having static methods calling each other is OK in case it's all utility functionality split up in multiple methods to avoid duplication. For example:

    public static File loadConfiguration(String name, Enum type) {
        String fileName = (form file name based on name and type);
        return loadFile(fileName); // static method in the same class
    }
    

提交回复
热议问题