Why is enum the best implementation for a singleton?
this seems like a trade-off to achieve on the fly serialization
For me it's a lot simpler and more concise to write something like
enum Singleton {
INSTANCE;
}
If you have a need to write a lot more code or introduce complexity then do so, but this is rarely required IMHO.
you lose the more friendly OOP approach of a classical singleton.
I find using fields to be simpler.
Enums can't be inherited,
True, but having multiple singletons is suspect in itself. Enums can inherit from interfaces which allows you to swap one implementation for another.
If you want to provide a skeleton class you need to create a helper class
A helper class doesn't have any state. A skeleton class might have some state in which case you need delegation.
BTW: You can use enum
for helper classes
enum Helper {;
public static my_static_methods_here;
}
why should we accept enum as the best implementation for a singleton
I would follow the YAGNI principle. Only develop what you need, not what you imagine you might need.
Enums can't be inherited
And it's one of the best parts of enums being singletons.
If you can inherit from a singleton, it's not a singleton any more.