Singleton
Generally: Classical singletons should be avoided.
By classical singleton I mean where a class statically forces there to be a singlet instance
// Example of double checked locking singleton initialization in java:
public class DclSingleton {
private static volatile DclSingleton instance;
public static DclSingleton getInstance() {
if (instance == null) {
synchronized (DclSingleton.class) {
if (instance == null) {
instance = new DclSingleton();
}
}
}
return instance;
}
// private constructor and other methods...
}
Instead: singleton instances should be managed by DI container or your manual DI wire up to create a single instance at highest level.