Java - is it bad practice not to have a class constructor? -


i want make helper class deals formatting (i.e. has methods remove punctuation , convert between types, reformatting names etc.). doesn't seem need fields - purpose passed things convert , return them, reformatted. bad practice leave out constructor? if so, should constructor doing? looking @ this link , noticed class describes lacks constructor.

is bad practice leave out constructor?

yes - because unless specify any constructors, java compiler give constructor same visibility class itself.

assuming methods static - seems unless want polymorphism - should make class final , give private constructor, other developers don't accidentally create instance of class, when pointless. when thinking api, time can remove ability developers stupid, :)

so like:

public final class helpers {     private helpers() {     }      public static string formatdate(date date) {         // etc     } } 

note taking polymorphism out of equation, you're removing possibility of changing behaviour tests etc. may fine - i'm not believer in "no statics, ever" - it's worth considering.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -