Should Helper/Utility Classes be abstract?

前端 未结 11 1985
时光说笑
时光说笑 2020-12-13 08:38

I commonly find myself extracting common behavior out of classes into helper/utility classes that contain nothing but a set of static methods. I\'ve often wondered if I sho

11条回答
  •  难免孤独
    2020-12-13 08:55

    someone mentioned that in C# 3.0 you could accomplish this via extension methods. I'm not a C# guy, did some back in the 1.5/2.0 days, but have not used it since then. Based on a very cursory understanding I think something similar can be accomplished in java with static imports. I realize its not at all the same thing, but if the goal is to just make these utility methods seem a bit more "native"(for lack of a better term) to the calling class, I think it will do the trick. Assuming the Utilities class I declared in my original question.

    import static Utilities.getSomeData;
    
    public class Consumer {
    
        public void doSomething(){
    
            String data =  getSomeData();
        }
    
    }
    

提交回复
热议问题