public static ISingleton instance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
这就是它存在的全部原因。# EYZ0。我们把它拿走,放到工厂方法中,例如:
public class SingletonFactory {
private static ISingleton instance;
// Knock-knock. Single Object here
public static ISingleton simpleSingleton() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}