Should Helper/Utility Classes be abstract?

前端 未结 11 1958
时光说笑
时光说笑 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 09:22

    As others stated, make a private parameter-less constructor. No-one can create an instance of it, apart from the class itself.

    As others have shown how it is done with other languages, here comes how you do it in the next C++ version, how to make a class non-instantiable:

    struct Utility { 
        static void doSomething() { /* ... */ } 
        Utility() = delete; 
    };
    

提交回复
热议问题