Sunday, 15 September 2013

Singleton With Arguments

Singleton With Arguments

Is it a good idea having a Singleton that accepts an argument in its
static constructor? Can I have concurrency problem?
public class DataHelper {
private static DataHelper singleton = null;
private Listener<Object> listener;
public static DataHelper getInstance(Listener<Object> listener) {
if(singleton == null) {
singleton = new DataHelper();
}
singleton.listener = listener;
return singleton;
}
}

No comments:

Post a Comment